QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#284119 | #5689. 喵了个喵 II | simonG# | WA | 67ms | 13996kb | C++14 | 1.4kb | 2023-12-16 10:25:12 | 2023-12-16 10:25:12 |
Judging History
answer
#include<algorithm>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<random>
using namespace std;
const int N=2e5+10,mod=998244353;
int n,m,a[N],fa[N];
int val[N],col[N];
vector<int> b;
vector<int> pos[N];
vector<pair<int,int>> g;
int getf(int x) {
if(fa[x]==x) return x;
return fa[x]=getf(fa[x]);
}
bool merge(int x,int y) {
int fx=getf(x),fy=getf(y);
if(fx==fy) return false;
else return fa[fx]=fy,true;
}
int main() {
scanf("%d",&n); n*=4;
for(int i=1; i<=n; i++) scanf("%d",&a[i]),b.push_back(a[i]);
sort(b.begin(),b.end());
m=unique(b.begin(),b.end())-b.begin();
b.resize(m);
for(int i=1; i<=n; i++) {
a[i]=lower_bound(b.begin(),b.end(),a[i])-b.begin()+1;
pos[a[i]].push_back(i);
}
for(int i=1; i<=m; i++) {
int cnt=pos[i].size();
if(cnt&1) return printf("NO\n"),0;
for(int j=0; j<cnt; j+=2)
g.push_back({pos[i][j],pos[i][j+1]});
}
sort(g.begin(),g.end());
int num=m,mr=g[0].second;
for(int i=1; i<=m; i++) fa[i]=i;
for(int i=1; i<(int)g.size(); i++) {
if(g[i].first<g[i-1].second) {
if(merge(a[g[i].first],a[g[i-1].first])) num--;
}
if(g[i].second<mr) return printf("NO\n"),0;
mr=max(mr,g[i].second);
}
printf("YES\n");
for(int i=1; i<=m; i++) getf(i);
for(int i=1; i<=4; i++) {
int o=0;
for(int j:pos[i]) {
col[j]=o;
o^=1;
}
}
for(int i=1; i<=n; i++) printf("%d",col[i]);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 67ms
memory: 13996kb
input:
50000 12725 41478 2443 1096 36968 36898 3393 45898 43154 26629 22985 37972 13935 25628 40196 40293 39791 29109 455 45812 12634 21086 8928 13600 25416 30244 15917 22568 35849 40189 27442 28785 46334 25651 7172 30994 39724 27853 47091 21306 42087 31612 22081 23002 17127 15269 11569 8254 41080 30112 31...
output:
YES 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
result:
wrong answer Incorrect