QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#373565 | #5200. BinCoin | InfinityNS# | WA | 1ms | 3872kb | C++14 | 3.1kb | 2024-04-01 20:18:24 | 2024-04-01 20:18:26 |
Judging History
answer
#include<bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) x.begin(),x.end()
using namespace std;
const int N=1001;
vector<int> parent(N);
vector<pair<int,int>> pos(N);
vector<bool> ok(N);
void solve(vector<vector<int>> tr,int par){
if(sz(tr[0])==1){
parent[tr[0][0]]=par;
return;
}
for(int i=0;i<sz(tr[0]);i++){
pos[tr[0][i]]={-1,-1};
ok[tr[0][i]]=1;
}
for(int i=0;i<sz(tr);i++){
for(int j=0;j<sz(tr[i]);j++){
int p=j;
int val=tr[i][j];
if(pos[val].f==-1||pos[val].f==p){
pos[val].f=p;
}
else{
if(pos[val].s==-1||pos[val].s==p){
pos[val].s=p;
}
else{
ok[val]=0;
}
}
}
}
vector<int> cand;
int poss=-1;
for(int i=0;i<sz(tr[0]);i++){
int t=tr[0][i];
if(ok[t]){
if(pos[t].s==-1)pos[t].s=pos[t].f;
if(pos[t].f+pos[t].s!=sz(tr[0])-1)continue;
if(min(pos[t].f,pos[t].s)>poss){
poss=min(pos[t].f,pos[t].s);
cand.clear();
}
if(min(pos[t].f,pos[t].s)==poss){
cand.pb(t);
}
}
}
for(auto root:cand){
//printf("%i!\n",root);
vector<vector<int>> lv,rv;
vector<int> nl,nr;
bool ok=1;
for(int j=0;j<sz(tr);j++){
vector<int> pre,posle;
bool nasao=0;
for(int i=0;i<sz(tr[j]);i++){
if(tr[j][i]==root){
nasao=1;
continue;
}
if(!nasao)pre.pb(tr[j][i]);
else posle.pb(tr[j][i]);
}
pair<vector<int>,vector<int>> tt={pre,posle};
sort(all(pre));
sort(all(posle));
if(pre>posle)swap(pre,posle),swap(tt.f,tt.s);
lv.pb(tt.f);
rv.pb(tt.s);
/*printf("pre: ");
for(int i=0;i<sz(pre);i++){
printf("%i ",pre[i]);
}
printf("posle: ");
for(int i=0;i<sz(posle);i++){
printf("%i ",posle[i]);
}
printf("\n");*/
if(j==0){
nl=pre;
nr=posle;
}
else{
if(nl!=pre||nr!=posle){
ok=0;
break;
}
}
}
//printf("%i\n",ok?1:0);
if(ok){
parent[root]=par;
solve(lv,root);
solve(rv,root);
break;
}
}
}
int main(){
int n,k;
scanf("%i %i",&n,&k);
vector<vector<int>> vals(k,vector<int>(n));
for(int i=0;i<k;i++){
for(int j=0;j<n;j++){
scanf("%i",&vals[i][j]);
}
}
solve(vals,-1);
for(int i=1;i<=n;i++){
printf("%i ",parent[i]);
}
printf("\n");
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3856kb
input:
3 50 1 2 3 1 2 3 3 2 1 1 2 3 3 2 1 1 2 3 1 2 3 1 2 3 1 2 3 3 2 1 1 2 3 3 2 1 1 2 3 3 2 1 1 2 3 3 2 1 1 2 3 1 2 3 3 2 1 1 2 3 3 2 1 1 2 3 3 2 1 1 2 3 1 2 3 3 2 1 1 2 3 1 2 3 1 2 3 1 2 3 3 2 1 1 2 3 3 2 1 3 2 1 1 2 3 3 2 1 1 2 3 3 2 1 3 2 1 1 2 3 1 2 3 3 2 1 1 2 3 3 2 1 3 2 1 3 2 1 1 2 3 1 2 3 3 2 1 3...
output:
2 -1 2
result:
ok everything is fine
Test #2:
score: 0
Accepted
time: 0ms
memory: 3852kb
input:
5 60 2 4 3 5 1 1 5 2 4 3 1 5 2 4 3 1 5 2 4 3 1 5 3 4 2 1 5 3 4 2 1 5 3 4 2 1 5 3 4 2 1 5 3 4 2 3 4 2 5 1 2 4 3 5 1 1 5 2 4 3 3 4 2 5 1 2 4 3 5 1 2 4 3 5 1 1 5 2 4 3 3 4 2 5 1 3 4 2 5 1 1 5 2 4 3 2 4 3 5 1 1 5 2 4 3 1 5 3 4 2 3 4 2 5 1 1 5 3 4 2 1 5 2 4 3 1 5 3 4 2 1 5 2 4 3 2 4 3 5 1 2 4 3 5 1 2 4 3...
output:
5 4 4 5 -1
result:
ok everything is fine
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 3872kb
input:
11 73 11 1 7 8 5 6 10 3 9 4 2 5 6 10 8 7 1 11 3 9 4 2 9 3 11 1 7 8 5 6 10 4 2 2 4 11 1 7 8 5 6 10 3 9 9 3 7 1 11 8 10 6 5 4 2 2 4 10 6 5 8 7 1 11 3 9 9 3 7 1 11 8 5 6 10 4 2 11 1 7 8 10 6 5 3 9 4 2 9 3 10 6 5 8 7 1 11 4 2 2 4 5 6 10 8 11 1 7 3 9 2 4 11 1 7 8 10 6 5 3 9 2 4 10 6 5 8 11 1 7 3 9 9 3 10...
output:
0 4 0 -1 0 0 0 0 0 0 0
result:
wrong answer 0 in the output