QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#56369#2833. HamiltonYaoBIG#WA 2ms3788kbC++1.7kb2022-10-18 23:14:102022-10-18 23:14:11

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-10-18 23:14:11]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3788kb
  • [2022-10-18 23:14:10]
  • 提交

answer

#include "bits/stdc++.h"
#define rep(i, a, n) for (auto i = a; i <= (n); ++i)
#define revrep(i, a, n) for (auto i = n; i >= (a); --i)
#define all(a) a.begin(), a.end()
#define sz(a) (int)(a).size()
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; }
using namespace std;

void debug_out() { cerr << endl; }
template<class H, class... T> void debug_out(H h, T... t) {
	cerr << " " << to_string(h);
	debug_out(t...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: "; debug_out(__VA_ARGS__)

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;


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

	int n;
	while (cin >> n) {
		vector<string> ss(n);
		for (auto &s: ss) cin >> s;
		vi vec{0, 1};
		rep(v, 2, n - 1) {
			int found = -1;
			rep(i, 0, sz(vec) - 1) {
				int a = vec[(i - 1 + sz(vec)) % sz(vec)];
				int b = vec[i];
				int c = vec[(i + 1) % sz(vec)];
				if (ss[a][b] == '0' && ss[b][c] == '1') {
					found = i;
					break;
				}
			}
			if (found == -1) vec.insert(vec.begin(), v);
			else {
				int a = vec[found];
				if (ss[v][a] == 0) vec.insert(vec.begin() + found + 1, v);
				else vec.insert(vec.begin() + found, v);
			}
		}
		int found = -1;
		rep(i, 0, sz(vec) - 1) {
			int a = vec[(i - 1 + sz(vec)) % sz(vec)];
			int b = vec[i];
			int c = vec[(i + 1) % sz(vec)];
			if (ss[a][b] == '0' && ss[b][c] == '1') {
				found = i;
				break;
			}
		}
		if (found != -1) rotate(vec.begin(), vec.begin() + found, vec.end());
		for (auto x: vec) printf("%d ", x + 1);
		puts("");
	}
	return 0;
}

详细

Test #1:

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

input:

3
001
000
100
4
0000
0000
0000
0000

output:

3 1 2 
4 3 1 2 

result:

ok 2 cases.

Test #2:

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

input:

3
000
000
000
3
010
100
000
3
011
100
100
3
011
101
110

output:

3 1 2 
1 2 3 
3 1 2 
3 1 2 

result:

ok 4 cases.

Test #3:

score: -100
Wrong Answer
time: 2ms
memory: 3696kb

input:

4
0000
0000
0000
0000
4
0000
0001
0000
0100
4
0100
1010
0100
0000
4
0111
1000
1000
1000
4
0010
0011
1101
0110
4
0111
1011
1100
1100
4
0111
1011
1101
1110
4
0000
0011
0101
0110
4
0101
1010
0100
1000
4
0011
0011
1100
1100
4
0010
0001
1000
0100

output:

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

result:

wrong answer case #11: found 3 indices