QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#619659 | #4632. Card Shark | ship2077 | WA | 1ms | 6192kb | C++23 | 1.3kb | 2024-10-07 14:56:05 | 2024-10-07 14:56:05 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
constexpr int M=2e5+5;
vector<pair<int,int>>adj[M];
int n,m,x,in[M],ou[M];
vector<int>ans;string str;
void dfs(int x){
while (!adj[x].empty()){
auto [z,y]=adj[x].back();adj[x].pop_back();
dfs(y);ans.emplace_back(z);
}
}
bool check(){ bool flag=1;
for (int i=1;i<=n;i++)
flag&=in[i]==ou[i];
if (flag) return 0;
if (in[x]!=ou[x]-1) return 1;
flag=0;
for (int i=1;i<=n;i++){
if (i==x) continue;
if (in[i]-1!=ou[i]||flag) return 1;
flag=1;
}
return 0;
}
int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin>>n>>m>>x;
for (int i=1;i<=n;i++){
string str;cin>>str;
int len=str.length(),pos;str=" "+str;
for (int j=1;j<=len;j++)
if (str[j]=='1') {pos=j;break;}
if (pos>m) return puts("-1"),0;
for (int j=1;j<=len;j++)
if ((str[j]-'0')^((j-pos)%m==0))
return puts("-1"),0;
int rpos=(len-pos)/m*m+pos;
in[m-(len-rpos)]++;ou[pos]++;
adj[pos].emplace_back(i,m-(len-rpos));
}
if (check()) return puts("-1"),0;
dfs(x);
if (ans.size()!=n) return puts("-1"),0;
reverse(ans.begin(),ans.end());
for (auto x:ans) printf("%d ",x);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 6192kb
input:
5 4 3 0100010 00100 001000100 0010 0100010
output:
4 3 5 2 1
result:
wrong answer 1st lines differ - expected: '2 1 3 5 4', found: '4 3 5 2 1 '