QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#769252 | #9557. Temperance | AiriS# | WA | 0ms | 12800kb | C++14 | 2.5kb | 2024-11-21 16:47:10 | 2024-11-21 16:47:14 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
template<typename T>void read(T &x){
x=0;char c=getchar();bool f=false;
while(c<'0'||c>'9'){if(c=='-')f=true;c=getchar();}
while(c>='0'&&c<='9') x=(x<<3)+(x<<1)+(c^48),c=getchar();
if(f) x=-x;
}
const int N=100003;
int T;
int n;
int a[N][3],c[N][3];
bool v[N];
vector<int> poi[N][3];
struct Node{
int k,p,c;
bool operator <(const Node &A)const{
if(c!=A.c) return c<A.c;
if(k!=A.k) return k<A.k;
return p<A.p;
}
};
int main(){
scanf("%d",&T);
while(T--){
scanf("%d",&n);
for(int i=1;i<=n;i++)
v[i]=false;
for(int i=1;i<=n;i++){
for(int j=0;j<3;j++){
scanf("%d",&a[i][j]);
c[a[i][j]][j]=0;
poi[a[i][j]][j].clear();
}
}
for(int i=1;i<=n;i++)
for(int j=0;j<3;j++)
poi[a[i][j]][j].push_back(i);
for(int i=1;i<=n;i++)
for(int j=0;j<3;j++)
c[a[i][j]][j]++;
set<Node> s;
for(int i=1;i<=n;i++){
for(int j=0;j<3;j++){
s.insert((Node){j,a[i][j],c[a[i][j]][j]});
}
}
int ans=0;
for(int i=0;i<n;i++){
while(!s.empty()){
auto it=s.begin();
if((it->c)!=c[it->p][it->k]){
s.erase(it);
continue;
}
if((it->c)>=i+1) break;
Node tmp=(*it);
int p=it->p,k=it->k;
vector<Node> np;
for(auto x:poi[p][k]){
if(!v[x]){
bool flag=true;
for(int j=0;j<3;j++){
if(c[a[x][j]][j]>c[p][k]){
flag=false;
break;
}
}
if(!flag) continue;
ans++;
v[x]=true;
for(int j=0;j<3;j++){
c[a[x][j]][j]--;
np.push_back((Node){j,a[x][j],c[a[x][j]][j]});
}
}
}
s.erase(tmp);
for(auto nd:np)
s.insert(nd);
}
printf("%d ",ans);
}
puts("");
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 11852kb
input:
2 5 1 1 1 1 1 2 1 1 3 2 3 5 2 2 4 3 1 1 1 2 2 2 3 3 3
output:
0 0 2 5 5 0 3 3
result:
ok 8 numbers
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 12800kb
input:
16 1 1 1 1 2 1 1 1 1 1 100000 3 1 1 1 1 1 100000 1 100000 1 4 1 1 1 1 1 100000 1 100000 1 1 100000 100000 5 1 1 1 1 1 100000 1 100000 1 1 100000 100000 100000 1 1 6 1 1 1 1 1 100000 1 100000 1 1 100000 100000 100000 1 1 100000 1 100000 7 1 1 1 1 1 100000 1 100000 1 1 100000 100000 100000 1 1 100000 ...
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 1 5 0 0 0 0 6 6 0 0 0 0 4 4 4 0 0 0 0 8 8 8 8 0 0 0 0 0 0 0 0 0 0 0 0 0 1 5 0 0 0 0 6 6 0 0 0 0 4 4 4 0 0 0 0 8 8 8 8
result:
wrong answer 26th numbers differ - expected: '7', found: '4'