QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#206388#3836. So I'll Max Out My Constructive Algorithm SkillsshenncWA 1ms3600kbC++141.1kb2023-10-07 20:15:282023-10-07 20:15:29

Judging History

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

  • [2023-10-07 20:15:29]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3600kb
  • [2023-10-07 20:15:28]
  • 提交

answer

#include<bits/stdc++.h>

using namespace std;
using ll = long long;
using pii = pair<int,int>;

int n;
int m[66][66];
int st[66][66] = {0};

int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};

void bfs(int x,int y){
	queue<pii>q;
	q.push({x,y});
	st[x][y] = 1;
	int num = -1;
	auto check = [](int x,int y){
		if(x<0 ||y<0)return false;
		if(x>=n || y>=n)return false;
		if(st[x][y])return false;
		return true;
	};
	
	while(!q.empty()){
		pii u = q.front();
		cout<<m[u.first][u.second] << (++num <= n*n ?" " :"\n");
		q.pop();
		int vx = -1,vy = -1,tmp = 0;
		for(int i = 0;i<4;i++){
			int tx = u.first  + dx[i];
			int ty = u.second + dy[i];
			if(check(tx,ty) && m[tx][ty]>tmp){
				vx = tx;
				vy = ty;
			}
		}
		if(vx!=-1 && vy!=-1){
			st[vx][vy] = 1;
			q.push({vx,vy});
		}
	}
}

void solve(){
	cin>>n;
	int x1 = -1,x2=  -1;
	for(int i = 0;i<n;i++){
		for(int j = 0;j<n;j++){
			st[i][j] = 0;
			cin>>m[i][j];
			if(m[i][j] == n*n){
				x1 = i;
				x2 = j;
			}
		}
	}
	bfs(x1,x2);
	
}



signed main(){
	cin.tie(0)->sync_with_stdio(0);
	
	int t;cin>>t;
	while(t--)
		solve();
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3588kb

input:

1
2
4 3
2 1

output:

4 3 1 2 

result:

ok correct

Test #2:

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

input:

100
9
30 75 35 51 25 19 76 65 62
11 56 63 60 77 48 28 26 74
16 44 46 41 17 8 66 61 42
29 7 43 38 40 31 27 10 39
52 23 58 80 50 20 33 69 47
79 1 5 49 22 37 71 18 70
54 72 4 64 55 34 12 6 15
14 53 45 13 32 59 73 57 81
36 3 78 24 2 68 9 67 21
7
11 28 2 19 9 41 24
17 34 5 10 42 18 47
33 35 22 8 49 1 29
...

output:

81 57 73 59 32 13 45 53 14 54 72 4 64 55 34 12 6 15 70 18 71 37 22 49 5 1 79 52 23 58 80 50 20 33 69 47 39 10 27 31 40 38 43 7 29 16 44 46 41 17 8 66 61 42 74 26 28 48 77 60 63 56 11 30 75 35 51 25 19 76 65 62 49 8 22 35 33 17 34 5 10 42 18 47 24 41 9 19 2 28 11 9 1 6 5 8 7 3 4 2 81 62 59 79 19 13 8...

result:

wrong answer [case 1] Duplicate number exists