QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#440990#5956. Paradox Sort233L32 ✓213ms3704kbC++142.1kb2024-06-14 09:02:062024-06-14 09:02:07

Judging History

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

  • [2024-06-14 09:02:07]
  • 评测
  • 测评结果:32
  • 用时:213ms
  • 内存:3704kb
  • [2024-06-14 09:02:06]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define uint unsigned int
#define ldb long double
#define pii pair<int,int>
#define mkp make_pair
#define mkt make_tuple
#define fr first
#define se second
#define uset unordered_set
#define umap unordered_map
#define pqueue priority_queue
#define all(_box) _box.begin(),_box.end()
#define ppc __builtin_popcount
#define ctz __builtin_ctz
#define clz __builtin_clz
#define lbd lower_bound
#define ubd upper_bound
#define deb(x) cerr<<#x<<'='<<(x)<<' '
using namespace std;
const int N=104;
int n,s,cnt;
string mp[N];
bool vis[N],used[N];

void dfs(int u){
    for(int v=0;v<n;v++){
        if(vis[v]||used[v]||mp[u][v]!='Y')continue;
        vis[v]=1,dfs(v);
    }
}
void solve(){
    cin>>n>>s;
    for(int i=0;i<n;i++)cin>>mp[i];
    memset(vis,0,sizeof(vis));
    memset(used,0,sizeof(used));
    vis[s]=1,dfs(s);
    if(count(vis,vis+n,0)){
        cout<<"IMPOSSIBLE\n";
        return;
    }

    int lst=-1;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++)if(!used[j]){
            if(j==s){
                if(lst!=-1&&mp[s][lst]!='Y')continue;
                bool skp=0;
                used[j]=1;
                for(int k=0;k<n;k++)
                    if(!used[k]&&mp[s][k]!='Y')skp=1;
                used[j]=0;
                if(skp)continue;
                lst=s;
            }
            else if(!used[s]){
                memset(vis,0,sizeof(vis));
                used[j]=1;
                vis[s]=1,dfs(s);
                int cur=lst;
                if(lst==-1||mp[j][lst]=='Y')cur=j;
                bool skp=0;
                for(int k=0;k<n;k++)
                    if(!used[k]&&!vis[k]&&mp[cur][k]!='Y')skp=1;
                used[j]=0;
                if(skp)continue;
                lst=cur;
            }
            used[j]=1;
            cout<<j<<' ';
            break;
        }
    }
    cout<<'\n';
}
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);

    int T;
    cin>>T;
    for(int i=1;i<=T;i++){
        cout<<"Case #"<<i<<": ";

        solve();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 4
Accepted

Test #1:

score: 4
Accepted
time: 1ms
memory: 3576kb

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: 0 2 3 4 1 
Case #5: 0 1 3 4 2 5 
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:

ok 100 lines

Subtask #2:

score: 28
Accepted

Test #2:

score: 28
Accepted
time: 213ms
memory: 3704kb

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: 0 13 23 28 30 34 38 40 41 42 43 46 49 51 52 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: 0 1 2 3 4 5 6 8...

result:

ok 100 lines

Extra Test:

score: 0
Extra Test Passed