QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#539887 | #8940. Piggy Sort | ucup-team3699# | RE | 0ms | 3548kb | C++20 | 2.6kb | 2024-08-31 15:57:16 | 2024-08-31 15:57:19 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define F first
#define S second
const int mol=998244353;
vector<int>a[505];
bool vis[505][505];
int sum[505], v[505], iuu[505];
int n, m;
bool ch(int d1, int d2, int pre){
// bool okk=0;
// if(pre==2) okk=1;
int p1=d1, p2=d2, p3=pre;
// cout<<d1<<" "<<d2<<" "<<pre<<"\n";
for(int i=3;i<=m;i++){
bool ok=0;
for(int j=1;j<=n;j++){
if(vis[i][j]) continue;
// if(okk) cout<<i<<" "<<j<<" "<<vis[i][j]<<" "<<(a[i][j]-a[i-1][pre])*d2<<" "<<d1*(sum[i]-sum[i-1])<<"\n";
if(a[i][j]>=a[i-1][pre]&&(a[i][j]-a[i-1][pre])*d2==d1*(sum[i]-sum[i-1])){
d1=a[i][j]-a[i-1][pre], d2=sum[i]-sum[i-1], pre=j;
ok=1;
break;
}
}
if(!ok) return 0;
}
d1=p1, d2=p2, pre=p3;
// cout<<d1<<" "<<d2<<" "<<pre<<"haha\n";
vis[2][pre]=1;
for(int i=3;i<=m;i++){
for(int j=1;j<=n;j++){
if(vis[i][j]) continue;
if(a[i][j]>=a[i-1][pre]&&(a[i][j]-a[i-1][pre])*d2==d1*(sum[i]-sum[i-1])){
d1=a[i][j]-a[i-1][pre], d2=sum[i]-sum[i-1], pre=j;
vis[i][j]=1;
// cout<<vis[i][2]<<"\n";
break;
}
}
}
return 1;
}
void solve(){
cin>>n>>m;
for(int i=1;i<=m;i++){
a[i].clear();sum[i]=0;
a[i].resize(n+1);
for(int j=1;j<=n;j++){
vis[i][j]=0;
int g;
cin>>g;
sum[i]+=g;
a[i][j]=g;
}
}
if(sum[2]-sum[1]==0){
for(int i=1;i<=n;i++) cout<<i<<" ";cout<<"\n";
return;
}
for(int i=1;i<=n;i++){
int dif1, dif2;
bool ok=0;
for(int j=1;j<=n;j++){
if(vis[2][j]) continue;
if(a[2][j]-a[1][i]<0) continue;
dif1=a[2][j]-a[1][i];
dif2=sum[2]-sum[1];
if(ch(dif1, dif2, j)) {
v[i]=a[2][j]-a[1][j];
ok=1;
break;
}
}
if(!ok) {
assert(0);
}
}
vector<pair<int, int>>ans;
for(int i=1;i<=n;i++) ans.pb({v[i], i});
sort(ans.begin(), ans.end());
int pp=1;
for(auto t: ans){
iuu[t.S]=pp++;
}
for(int i=1;i<=n;i++) cout<<iuu[i]<<" ";cout<<"\n";
}
signed main(){
ios::sync_with_stdio(0);cin.tie(0);
int t;
cin>>t;
while(t--)
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3548kb
input:
3 2 4 1 2 3 4 5 6 7 8 1 2 1 1 3 4 1 2 3 6 9 9 10 15 17 12 18 21
output:
1 2 1 3 1 2
result:
ok 3 lines
Test #2:
score: -100
Runtime Error
input:
41 1 2 -19 9531 2 3 11 13 3175 4759 2211 3313 10 19 -54 -25 -19 -18 -1 3 61 63 85 88 -54 753 863 2397 3111 4649 4671 4756 5507 7762 -54 369 479 1245 1575 2345 2367 2452 2819 3922 -54 553 663 1797 2311 3449 3471 3556 4107 5762 -54 87 197 399 447 653 675 760 845 1102 -54 320 430 1098 1379 2051 2073 21...