比赛 |
近5年noip/csp题目回顾 |
评测结果 |
WWWWWWAWAWWWWWWWWWWW |
题目名称 |
最小环(民间数据) |
最终得分 |
10 |
用户昵称 |
┭┮﹏┭┮ |
运行时间 |
1.295 s |
代码语言 |
C++ |
内存使用 |
0.00 MiB |
提交时间 |
2022-06-27 11:00:45 |
显示代码纯文本
- #include <bits/stdc++.h>
- using namespace std;
- const int N = 200010;
- long long s;
- int n,m;
- int a[N*2],k;
- int main(){
- freopen("noi_online2020_ring.in","r",stdin);
- freopen("noi_online2020_ring.out","w",stdout);
- cin>>n>>m;
- for(int i = 1;i <= n;i++){
- cin>>a[i];
- }
- sort(a+1,a+1+n);
- for(int i = 1;i <= m;i++){
- s = 0;
- cin>>k;
- if(k == 0){
- for(int j = 1;j <= n;j++){
- s += a[j] * a[j];
- }
- }
- else if(k == 1){
- s = a[n] * a[n-1] + a[1] * a[2];
- for(int j = n;j >= 3;j--){
- s += a[j] * a[j-2];
- }
- }
- else if(k == 2){
- if(n % 2 == 0){
- int l = n / k;
- for(int j = n;j >= 1;j-=l){
- for(int o = j;o >= j-l+2;o--){
- s += a[o] * a[o-1];
- }
- s += a[j] * a[j-l+1];
- }
- }
- else{
- for(int j = n;j >= 3;j--){
- s += a[j] * a[j-2];
- }
- s += a[n] * a[n-1];
- }
- }
- cout<<s<<endl;
- }
-
- return 0;
- }