QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#541101 | #8940. Piggy Sort | ucup-team3510# | WA | 1ms | 4144kb | C++20 | 1.6kb | 2024-08-31 18:39:55 | 2024-08-31 18:39:55 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 505, V = 1e7;
int x[N][N], ord[N], val[N], ans[N];
ll P[N];
unordered_set<int> mp[N];
ll gcd(ll x, ll y)
{
return x ? gcd(y % x, x) : y;
}
bool cmp(int x, int y)
{
return P[x] < P[y];
}
bool cmp2(int a, int b)
{
return (val[a] != val[b]) ? val[a] < val[b] : x[1][a] < x[1][b];
}
int main()
{
int t, n, m, i, j, k;
ll d, e;
scanf("%d", &t);
while(t--)
{
scanf("%d%d", &n, &m);
for(i = 1; i <= m; i++)
{
ord[i] = i;
P[i] = 0;
mp[i] = {};
for(j = 1; j <= n; j++)
{
scanf("%d", x[i] + j);
mp[i].insert(x[i][j]);
P[i] += x[i][j];
}
}
for(i = m; i >= 1; i--)
P[i] -= P[1];
if(P[1] == P[2])
{
for(i = 1; i <= n; i++)
printf("%d ", i);
printf("\n");
continue;
}
sort(ord + 1, ord + m + 1, cmp);
d = 0;
for(i = 1; i <= m; i++)
d = gcd(d, P[i]);
for(i = 1; i <= m; i++)
P[i] /= d;
for(i = 1; i <= n; i++)
for(j = 1; j <= n; j++)
{
d = x[ord[2]][j] - x[ord[1]][i];
if(abs(d) % (P[ord[2]] - P[ord[1]]))
continue;
d /= P[ord[2]] - P[ord[1]];
for(k = 3; k <= m; k++)
{
e = d * (P[ord[k]] - P[ord[1]]) + x[ord[1]][i];
if(abs(e) > V)
break;
if(!mp[k].count((int)e))
break;
}
if(k > m)
{
val[i] = d;
break;
}
}
for(i = 1; i <= n; i++)
ord[i] = i;
sort(ord + 1, ord + n + 1, cmp2);
for(i = 1; i <= n; i++)
ans[ord[i]] = i;
for(i = 1; i <= n; i++)
printf("%d ", ans[i]);
printf("\n");
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3824kb
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
Wrong Answer
time: 1ms
memory: 4144kb
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...
output:
1 2 1 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8 9 10 1 2 3 4 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 10...
result:
wrong answer 2nd lines differ - expected: '1 2', found: '2 1 '