QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#605566 | #8940. Piggy Sort | qiuuu | Compile Error | / | / | C++14 | 1.5kb | 2024-10-02 17:58:35 | 2024-10-02 17:58:35 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=509;
int n,m,t,sum[N];
int a[N][N],ans[N];
int pp[N];
bool vis[N][N];
pair<int,int> su[N];
int main()
{
scanf("%d",&t);
while(t--)
{
memset(vis,0,sizeof(vis));
memset(sum,0,sizeof(sum));
scanf("%d%d",&n,&m);
for(int i=1;i<=m;i++)
{
for(int j=1;j<=n;j++)
scanf("%d",&a[i][j]);
for(int j=1;j<=n;j++)
sum[i]+=a[i][j];
}
if(m==1||sum[1]==sum[2]||n==1)
{
for(int i=1;i<=n;i++) printf("%d ",i);
puts("");
continue;
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
if(vis[2][j]) continue;
long long x=a[2][j]-a[1][i],v=a[2][j];
if(x<0) continue;
int y=sum[2]-sum[1];
int fg=0;
for(int k=3;k<=m;k++)
{
if(x*(sum[k]-sum[k-1])%y) break;
long long u=x*(sum[k]-sum[k-1])/y;
v+=u;
int uu=lower_bound(a[k]+1,a[k]+n+1,v)-a[k];
int vv=upper_bound(a[k]+1,a[k]+n+1,v)-a[k];
bool flg=0;
for(int j=uu;j<vv;j++)
{
if(!vis[k][j])
{
pp[k]=j
flg=1;
break;
}
}
if(!flg) break;
if(k==m) fg=1;
}
if(fg==1)
{
su[i]=make_pair(x,i);
vis[2][j]=1;
for(int i=3;i<=m;j++) vis[i][pp[i]]=1;
break;
}
}
}
sort(su+1,su+n+1);
for(int i=1;i<=n;i++) ans[su[i].second]=i;
for(int i=1;i<=n;i++) printf("%d ",ans[i]);
puts("");
}
}
/*
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
*/
Details
answer.code: In function ‘int main()’: answer.code:52:64: error: expected ‘;’ before ‘flg’ 52 | pp[k]=j | ^ | ; 53 | flg=1; | ~~~ answer.code:11:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 11 | scanf("%d",&t); | ~~~~~^~~~~~~~~ answer.code:16:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 16 | scanf("%d%d",&n,&m); | ~~~~~^~~~~~~~~~~~~~ answer.code:20:38: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 20 | scanf("%d",&a[i][j]); | ~~~~~^~~~~~~~~~~~~~~