QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#422485#5956. Paradox SortjuruoA0 186ms3780kbC++143.2kb2024-05-27 14:59:552024-05-27 14:59:55

Judging History

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

  • [2024-05-27 14:59:55]
  • 评测
  • 测评结果:0
  • 用时:186ms
  • 内存:3780kb
  • [2024-05-27 14:59:55]
  • 提交

answer

#include <bits/stdc++.h>
using std::bitset;
using std::cout;
using std::deque;
using std::endl;
using std::greater;
using std::lower_bound;
using std::make_pair;
using std::map;
using std::max;
using std::min;
using std::multimap;
using std::multiset;
using std::nth_element;
using std::pair;
using std::priority_queue;
using std::queue;
using std::reverse; 
using std::set;
using std::sort;
using std::sqrt;
using std::stable_sort;
using std::string;
using std::swap;
using std::unique;
using std::upper_bound;
using std::vector;
typedef long long li;
typedef long double lf; 

inline li read(){
	li ans = 0, f = 1;
	char ch = getchar();
	while(ch < '0' || ch > '9'){
		f = (ch == '-') ? -1 : 1;
		ch = getchar();
	}
	while(ch <= '9' && ch >= '0'){
		ans = ans * 10 + (ch ^ 48);
		ch = getchar();
	}
	return ans * f;
} 

li n, need;
bool win[110][110];
li f[110], a[110];
li next[110], pre[110], vis[110];
li fl;

void dfs(li u, li now){
    if(u > n){
        if(now == need){
            fl = 1;
            for(li i = 1; i <= n; i++) printf("%lld ", a[i] - 1); printf("\n");
            // cout << now << endl;
            // for(li i = 1; i <= n; i++) cout << a[i] << " "; cout << endl;
        }
        return;
    }
    if(vis[need] && now != need) return;
    for(li i = next[0]; i <= n; i = next[i]){
        if(i == need && u <= n - 13) continue;
        vis[i] = 1;
        a[u] = i;
        next[pre[i]] = next[i];
        pre[next[i]] = pre[i];
        if(win[now][i]) dfs(u + 1, now);
        else dfs(u + 1, i);
        if(fl) return;
        next[pre[i]] = i;
        pre[next[i]] = i;
        vis[i] = 0;
    }
}

queue<li> q;
li wins[200010];

int main(){
    // freopen("wonderful.ans", "r", stdin);
    // freopen("www.ww", "w", stdout); 
	li T = read();
    for(li k = 1; k <= T; k++){
        fl = 0;
        n = read(), need = read() + 1;
        wins[need] = 0;
        for(li i = 1; i <= n; i++){
            for(li j = 1; j <= n; j++){
                char ch = getchar();
                while(ch != '-' && ch != 'Y' && ch != 'N') ch = getchar();
                if(ch == 'Y') win[i][j] = 1, wins[i]++;
                else win[i][j] = 0;
            }
        }
        for(li i = 0; i <= n + 1; i++){
            pre[i] = i - 1, next[i] = i + 1;
            vis[i] = 0;
        }
        while(q.size()) q.pop();
        q.push(need);
        li cnt = 0;
        vis[need] = 1;
        while(!q.empty()){
            li k = q.front(); cnt++; q.pop();
            for(li i = 1; i <= n; i++) if(win[k][i] && !vis[i]){
                vis[i] = 1;
                q.push(i);
            }
        }
        // cout << cnt << endl;
        for(li i = 1; i <= n; i++) vis[i] = 0;
        // cout << win[35][36] << endl;
        printf("Case #%lld: ", k);
        if(cnt == n){
            if(wins[need] == 1){
                printf("%lld %lld ", n - 2, n - 1);
                for(li i = n - 2; i >= 1; i--) printf("%lld ", i - 1);
                printf("\n");
                fl = 1;
            }
             else dfs(1, 0);
        }
        if(fl){
            ;
        } else{
            puts("IMPOSSIBLE");
        }
    }
    return 0;
} 

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3776kb

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: 1 2 0 
Case #2: 0 1 
Case #3: 3 4 2 1 0 
Case #4: 3 4 2 1 0 
Case #5: 4 5 3 2 1 0 
Case #6: 0 1 2 3 
Case #7: 0 1 
Case #8: 0 1 2 3 4 
Case #9: IMPOSSIBLE
Case #10: 6 7 5 4 3 2 1 0 
Case #11: 0 1 2 
Case #12: 0 1 
Case #13: 0 1 
Case #14: IMPOSSIBLE
Case #15: IMPOSSIBLE
Case #16: 7 8 6 5 4 ...

result:

wrong answer 4th lines differ - expected: 'Case #4: 0 2 3 4 1', found: 'Case #4: 3 4 2 1 0 '

Subtask #2:

score: 0
Wrong Answer

Test #2:

score: 0
Wrong Answer
time: 186ms
memory: 3780kb

input:

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

output:

Case #1: 37 38 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: 51 52 50 49 48 47 46 45 44 43 42 41 40 39 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 #3: 25 26 24 23 22 ...

result:

wrong answer 2nd lines differ - expected: 'Case #2: 0 13 23 28 30 34 38 4...45 20 24 39 22 12 44 36 2 21 14', found: 'Case #2: 51 52 50 49 48 47 46 ...3 12 11 10 9 8 7 6 5 4 3 2 1 0 '