QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#379205 | #8574. Swirly Sort | ucup-team266# | WA | 6ms | 5672kb | C++20 | 1.6kb | 2024-04-06 16:35:23 | 2024-04-06 16:35:23 |
Judging History
answer
/*
Things to notice:
1. do not calculate useless values
2. do not use similar names
Things to check:
1. submit the correct file
2. time (it is log^2 or log)
3. memory
4. prove your naive thoughts
5. long long
6. corner case like n=0,1,inf or n=m
7. check if there is a mistake in the ds or other tools you use
8. fileio in some oi-contest
9. module on time
10. the number of a same divisor in a math problem
11. multi-information and queries for dp and ds problems
*/
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define pii pair<long long,long long>
#define mp make_pair
#define pb push_back
const int mod=998244353;
const int inf=0x3f3f3f3f;
const int INF=1e18;
int n,k;
int a[300005],b[300005];
int calc()
{
for(int i=1;i<=n;i++) b[i]=a[i];
priority_queue <int> q;
int res=0;
for(int i=1;i<=n;i++)
{
if(a[i]<0) res-=a[i],a[i]=0;
if(q.size()&&q.top()>a[i]) res+=q.top()-a[i],q.pop(),q.push(a[i]);
q.push(a[i]);
}
for(int i=1;i<=n;i++) a[i]=b[i];
return res;
}
void solve()
{
cin>>n>>k;
for(int i=1;i<=n;i++) cin>>a[i];
if(k==1) cout<<calc()<<"\n";
else if(k==n)
{
int ans=INF;
for(int i=1;i<=n;i++)
{
ans=min(ans,calc());
int tmp=a[n];
for(int j=n-1;j>=1;j--) a[j+1]=a[j];
a[1]=tmp;
}
cout<<ans<<"\n";
}
else if(k%2==0) cout<<"0\n";
else
{
sort(a+1,a+1+n);
int ans=INF;
for(int i=1;i<n;i++) ans=min(ans,a[i+1]-a[i]);
cout<<ans<<"\n";
}
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int _=1;
cin>>_;
while(_--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5600kb
input:
4 4 1 6 4 3 7 4 2 6 4 3 7 4 3 6 4 3 7 4 4 6 4 3 7
output:
3 0 1 2
result:
ok 4 number(s): "3 0 1 2"
Test #2:
score: -100
Wrong Answer
time: 6ms
memory: 5672kb
input:
10000 4 3 524728 254456 277709 19127 15 11 360089 525234 862619 897281 336644 910706 75922 708901 754517 734744 94169 326125 746826 846063 159956 4 2 140105 792522 40264 514789 12 2 270333 888927 500833 9065 936673 982631 332435 751429 607700 840339 804685 416612 8 7 119416 689632 517277 673646 8262...
output:
23253 7691 0 0 15986 278544 0 0 0 0 0 2022 14023 0 0 9260 0 0 51255 0 0 277173 480146 0 658 4525 25495 0 1928 0 0 266148 0 767231 5853 0 0 121885 0 788638 0 0 0 779611 0 5881 0 0 0 0 517074 0 5586 0 210836 454586 662851 0 781542 0 0 864957 175421 0 0 0 0 0 0 0 541010 0 0 15407 96908 0 3413333 0 321 ...
result:
wrong answer 13th numbers differ - expected: '0', found: '14023'