QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#80268#3836. So I'll Max Out My Constructive Algorithm SkillsdarielangelTL 2ms3568kbC++171.5kb2023-02-23 12:09:162023-02-23 12:09:17

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-02-23 12:09:17]
  • 评测
  • 测评结果:TL
  • 用时:2ms
  • 内存:3568kb
  • [2023-02-23 12:09:16]
  • 提交

answer

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

int t,n;
int M[64][64];
int S[64][64];
int B[64][64];
long long V[64];
bool ok;
int x[4]= {-1,0,1,0};
int y[4]= {0,1,0,-1};
vector<int>ans;

struct st{
	int F,S,V;
}vec[64*64];

void dfs(int a, int b){
	ans.push_back(M[a][b]);
	V[a] |= (1<<b);
	
	/*cout<<"-> "<<S[a][b]<<" : "<<B[a][b]<<'\n';
	for(int i=0;i<ans.size();i++){
			cout<<ans[i];
			if(i<ans.size()-1)cout<<' ';
		}cout<<'\n';*/
	
	if(ans.size() == n*n){
		if(S[a][b]>=B[a][b]){
			ok=1;
		}
		return;
	}
	
	
	int nx,ny;
	for(int i=0;i<4;i++){
		nx = a+x[i];
		ny = b+y[i];
		
		if(nx<0||ny<0||nx==n||ny==n)continue;
		
		if(V[nx] & (1<<ny))continue;
		
		if(M[a][b] >= M[nx][ny]){
			S[nx][ny] = S[a][b]+1;
			B[nx][ny] = B[a][b];
		} else {
			S[nx][ny] = S[a][b];
			B[nx][ny] = B[a][b]+1;
		}
		
		dfs(nx,ny);
		if(ok)return;
	}
	
	V[a] ^= (1<<b);
	ans.pop_back();
}

bool sort(st a, st b){
	return a.V > b.V;
}

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

	while(t--) {
		cin>>n;

		int c=0;
		for(int i=0; i<n; i++)
			for(int j=0; j<n; j++) {
				cin>>M[i][j];
				vec[c].F = i;
				vec[c].S = j;
				vec[c++].V = M[i][j];
			}

		ok=0;
		
		for(int i=0;i<n*n;i++){
			ans.clear();
			fill(V,V+n,0);
			dfs(vec[i].F,vec[i].S);
			if(ok)break;
		}
		
		for(int i=0;i<ans.size();i++){
			printf("%d",ans[i]);
			if(i<ans.size()-1)printf(" ");
		}printf("\n");
	}

}

详细

Test #1:

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

input:

1
2
4 3
2 1

output:

4 3 1 2

result:

ok correct

Test #2:

score: -100
Time Limit Exceeded

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:


result: