QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#162943#5200. BinCoinkaruna#WA 2ms3688kbC++171.8kb2023-09-03 17:59:052023-09-03 17:59:05

Judging History

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

  • [2023-09-03 17:59:05]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3688kb
  • [2023-09-03 17:59:05]
  • 提交

answer

#include <bits/stdc++.h>
#define ff first
#define ss second
using namespace std;

int par[1010];
bool chc[1010];

int f(vector<vector<int>> V)
{
	vector<int> pr = V[0];
	if(pr.size() == 1) return pr[0];
	sort(pr.begin(), pr.end());
	for(auto &i : V) for(auto &j : i) j = lower_bound(pr.begin(), pr.end(), j) - pr.begin();
	int n = pr.size();
	int k = V.size();
	vector<int> ls[n];
	for(int i = 0; i < k; ++i)
	{
		for(int j = 0; j < n; ++j)
			ls[V[i][j]].push_back(j);
	}
	for(int i = 0; i < n; ++i)
	{
		sort(ls[i].begin(), ls[i].end());
		ls[i].resize(unique(ls[i].begin(), ls[i].end()) - ls[i].begin());
		if(ls[i].size() <= 2 && ls[i][0] != 0)
		{
			int t0 = find(V[0].begin(), V[0].end(), i) - V[0].begin();
			for(int j = 0; j < n; ++j) chc[j] = false;
			for(int j = 0; j < t0; ++j) chc[V[0][j]] = true;

			bool flag = true;
			vector<vector<int>> A, B;
			for(int j = 0; j < k; ++j)
			{
				int t = find(V[j].begin(), V[j].end(), i) - V[j].begin();
				bool fl = chc[V[j][0]];
				for(int p = 0; p < t; ++p) if(fl != chc[V[j][p]]) { flag = false; break; }
				for(int p = t + 1; p < n; ++p) if(fl == chc[V[j][p]]) { flag = false; break; }
				if(fl)
				{
					A.emplace_back(V[j].begin(), V[j].begin() + t);
					B.emplace_back(V[j].begin() + t + 1, V[j].end());
				} else {
					B.emplace_back(V[j].begin(), V[j].begin() + t);
					A.emplace_back(V[j].begin() + t + 1, V[j].end());
				}
			}
			if(!flag) continue;
			
			par[pr[f(A)]] = pr[i];
			par[pr[f(B)]] = pr[i];
			return pr[i];
		}
	}
}

int main() {
	cin.tie(0); ios_base::sync_with_stdio(0);

	int n, k; cin >> n >> k;
	vector<vector<int>> V;
	for(int i = 0; i < k; ++i)
	{
		vector<int> T(n);
		for(auto &i : T) cin >> i, --i;
		V.push_back(T);
	}

	par[f(V)] = -2;

	for(int i = 0; i < n; ++i) cout << par[i] + 1 << ' ';
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 3612kb

input:

3 50
1 2 3
1 2 3
3 2 1
1 2 3
3 2 1
1 2 3
1 2 3
1 2 3
1 2 3
3 2 1
1 2 3
3 2 1
1 2 3
3 2 1
1 2 3
3 2 1
1 2 3
1 2 3
3 2 1
1 2 3
3 2 1
1 2 3
3 2 1
1 2 3
1 2 3
3 2 1
1 2 3
1 2 3
1 2 3
1 2 3
3 2 1
1 2 3
3 2 1
3 2 1
1 2 3
3 2 1
1 2 3
3 2 1
3 2 1
1 2 3
1 2 3
3 2 1
1 2 3
3 2 1
3 2 1
3 2 1
1 2 3
1 2 3
3 2 1
3...

output:

2 -1 2 

result:

ok everything is fine

Test #2:

score: 0
Accepted
time: 1ms
memory: 3624kb

input:

5 60
2 4 3 5 1
1 5 2 4 3
1 5 2 4 3
1 5 2 4 3
1 5 3 4 2
1 5 3 4 2
1 5 3 4 2
1 5 3 4 2
1 5 3 4 2
3 4 2 5 1
2 4 3 5 1
1 5 2 4 3
3 4 2 5 1
2 4 3 5 1
2 4 3 5 1
1 5 2 4 3
3 4 2 5 1
3 4 2 5 1
1 5 2 4 3
2 4 3 5 1
1 5 2 4 3
1 5 3 4 2
3 4 2 5 1
1 5 3 4 2
1 5 2 4 3
1 5 3 4 2
1 5 2 4 3
2 4 3 5 1
2 4 3 5 1
2 4 3...

output:

5 4 4 5 -1 

result:

ok everything is fine

Test #3:

score: -100
Wrong Answer
time: 1ms
memory: 3688kb

input:

11 73
11 1 7 8 5 6 10 3 9 4 2
5 6 10 8 7 1 11 3 9 4 2
9 3 11 1 7 8 5 6 10 4 2
2 4 11 1 7 8 5 6 10 3 9
9 3 7 1 11 8 10 6 5 4 2
2 4 10 6 5 8 7 1 11 3 9
9 3 7 1 11 8 5 6 10 4 2
11 1 7 8 10 6 5 3 9 4 2
9 3 10 6 5 8 7 1 11 4 2
2 4 5 6 10 8 11 1 7 3 9
2 4 11 1 7 8 10 6 5 3 9
2 4 10 6 5 8 11 1 7 3 9
9 3 10...

output:

6 4 4 -1 1 3 1 3 3 1 1 

result:

wrong answer there is a node with 4 children