QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#121844#6503. DFS Order 3P3KOWA 2ms4328kbC++201.1kb2023-07-08 22:12:032023-07-08 22:12:04

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-08 22:12:04]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:4328kb
  • [2023-07-08 22:12:03]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

const int MAXN=1005;

int n;
deque<int> order[MAXN];
bool vis[MAXN][MAXN];
int ans1[MAXN],ans2[MAXN],tot;

void init(int x){
	for(int i=1;i<=x;i++)
		while(order[i].size())order[i].pop_front();
}

int main(){
	//std::ios::sync_with_stdio(false);
	//std::cin.tie(NULL);

	int t;scanf("%d",&t);
	while(t--){
		
		cin>>n;
		for(int i=1;i<=n;i++)for(int j=1;j<=n;j++){
			int x;scanf("%d",&x);
			order[i].push_back(x);
		}
		int cnt=0;
		while(cnt<n-1){
			int tag=0;
			for(int i=1;i<=n;i++){
				if(!order[i].empty()&&!tag)tag=order[i].back();
				if(!order[i].empty()&&order[i].back()==tag)order[i].pop_back();
			}
			int nxt=0;
			for(int i=1;i<=n;i++)
				if(!order[i].empty()&&order[i].front()==tag){
					order[i].pop_front();
					if(!order[i].empty())nxt=order[i].front();
				}
			if(!vis[tag][nxt]&&nxt){
				ans1[++cnt]=tag;ans2[cnt]=nxt;
				vis[tag][nxt]=vis[nxt][tag]=1;
			}
		}
		for(int i=1;i<=cnt;i++){
			printf("%d %d\n",ans1[i],ans2[i]);
			vis[ans1[i]][ans2[i]]=0;
			vis[ans2[i]][ans1[i]]=0;
		}
		//init(n);
	}
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 2ms
memory: 4328kb

input:

4
2
1 2
2 1
3
1 2 3
2 1 3
3 2 1
4
1 2 3 4
2 1 3 4
3 2 4 1
4 2 1 3
5
1 2 4 3 5
2 4 1 3 5
3 5 1 2 4
4 2 1 3 5
5 3 1 2 4

output:

2 1
3 2
2 1
4 2
2 1
1 3
5 3
3 1
4 2
2 1

result:

wrong answer ord[1] didn't pass the test (test case 3)