QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#422286#5956. Paradox Sortluanmenglei0 2ms3604kbC++171.8kb2024-05-27 10:50:092024-05-27 10:50:09

Judging History

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

  • [2024-05-27 10:50:09]
  • 评测
  • 测评结果:0
  • 用时:2ms
  • 内存:3604kb
  • [2024-05-27 10:50:09]
  • 提交

answer

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

namespace SOL {

using i64 = long long;
void debug(const char *msg, ...) {
#ifdef CLESIP
    va_list arg;
    static char pbString[512];
    va_start(arg,msg);
    vsprintf(pbString,msg,arg);
    cerr << "[DEBUG] " << pbString << "\n";
    va_end(arg);
#endif    
}
template<typename T, typename L>
bool chkmax(T &x, L y) { if (x < y) return x = y, true; return false; }
template<typename T, typename L>
bool chkmin(T &x, L y) { if (y < x) return x = y, true; return false; }

const int N = 110;
int n, st, ans[N];
bool g[N][N], vis[N];
char s[N];

void insert(int len, int pos, int val) {
	static int tmp[N];
	for (int i = pos; i <= len; i ++)
		tmp[i] = ans[i];
	ans[pos] = val;
	for (int i = pos + 1; i <= len + 1; i ++)
		ans[i] = tmp[i - 1];
}

void solve(int kase) {
	cout << "Case #" << kase << ": ";
	cin >> n >> st; st += 1;
	for (int i = 1; i <= n; i ++)
		vis[i] = false;
	for (int i = 1; i <= n; i ++) {
		cin >> (s + 1);
		for (int j = 1; j <= n; j ++) {
			if (s[j] == 'Y')
				g[j][i] = 1;
			else
				g[j][i] = 0;
		}
	}
	ans[1] = st; vis[st] = 1;
	for (int t = 1; t < n; t ++) {
		int cur = -1, pos = -1;
		for (int i = 1; i <= n && cur == -1; i ++) if (!vis[i]) {
			if (g[i][ans[1]]) {
				cur = i, pos = 1;
				break;
			}
			for (int j = 2; j <= t; j ++) {
				if (g[i][ans[j]]) {
					cur = i, pos = j;
					break;
				}
			}
		}
		if (cur == -1) {
			cout << "IMPOSSIBLE\n";
			return;
		}
		vis[cur] = 1;
		insert(t, pos, cur);
		// debug("t: %d pos: %d cur: %d", t, pos, cur);
	}
	for (int i = 1; i <= n; i ++)
		cout << ans[i] - 1 << " \n"[i == n];
}

}
int main() {
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	int tt; cin >> tt;
	for (int t = 1; t <= tt; t ++)
		SOL::solve(t);
	return 0;
}

详细

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3600kb

input:

100
3 0
-YN
N-Y
YN-
2 0
-Y
N-
5 0
-YNNN
N-YNN
YN-YN
YYN-Y
YYYN-
5 1
-NYYY
Y-NNN
NY-NY
NYY-N
NYNY-
6 5
-YYNNY
N-YYNY
NN-NYN
YNY-NY
YYNY-Y
NNYNN-
4 0
-YYY
N-YN
NN-N
NYY-
2 0
-Y
N-
5 1
-NYNY
Y-YYY
NN-YY
YNN-N
NNNY-
7 5
-YYYYYY
N-NNYYN
NY-YNNN
NYN-NYN
NNYY-NN
NNYNY-N
NYYYYY-
8 0
-YNNNNNN
N-YNNNNN
YN-YNN...

output:

Case #1: 2 1 0
Case #2: 1 0
Case #3: 4 3 2 1 0
Case #4: 4 2 3 0 1
Case #5: 3 1 0 4 2 5
Case #6: 2 1 3 0
Case #7: 1 0
Case #8: 3 4 2 0 1
Case #9: IMPOSSIBLE
Case #10: 7 6 5 4 3 2 1 0
Case #11: 1 2 0
Case #12: 1 0
Case #13: 1 0
Case #14: IMPOSSIBLE
Case #15: IMPOSSIBLE
Case #16: 8 7 6 5 4 3 1 2 0
Case...

result:

wrong answer 1st lines differ - expected: 'Case #1: 1 2 0', found: 'Case #1: 2 1 0'

Subtask #2:

score: 0
Wrong Answer

Test #2:

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

input:

100
39 0
-YNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
N-YNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
YN-YNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
YYN-YNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
YYYN-YNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
YYYYN-YNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
YYYYYN-YNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
YYYYYYN-YNN...

output:

Case #1: 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Case #2: 52 49 51 42 46 41 43 40 38 34 13 28 30 23 0 33 5 1 17 32 15 29 19 10 16 47 48 9 4 27 6 7 18 31 8 11 26 50 3 37 25 35 45 20 24 39 22 12 44 36 2 21 14
Case #3: 21 24 26 18 16 20...

result:

wrong answer 1st lines differ - expected: 'Case #1: 37 38 36 35 34 33 32 ...13 12 11 10 9 8 7 6 5 4 3 2 1 0', found: 'Case #1: 38 37 36 35 34 33 32 ...13 12 11 10 9 8 7 6 5 4 3 2 1 0'