QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#541101#8940. Piggy Sortucup-team3510#WA 1ms4144kbC++201.6kb2024-08-31 18:39:552024-08-31 18:39:55

Judging History

你现在查看的是最新测评结果

  • [2024-08-31 18:39:55]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:4144kb
  • [2024-08-31 18:39:55]
  • 提交

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 '