QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#716336 | #9578. 爱上字典 | qzez# | WA | 0ms | 3868kb | C++14 | 3.5kb | 2024-11-06 14:58:24 | 2024-11-06 14:58:24 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define all(x) (x).begin(),(x).end()
const int N=1e5+10;
int sum,n,m,k,t,a[N],cur;
int res;
void get(int x){
// cerr<<"get"<<' '<<x<<endl;
int ne=min(x,k-sum);
res+=x-ne;
sum+=ne,n+=ne;
}
const int id[3][3]={
{2,3,4},
{5,1,6},
{7,8,9}
};
int val[3][3];
pair<int,int>pos[10];
int ans[N];
void insert(int x){
ans[x]++;
}
void end(){
for(int i=0;i<=m;i++)printf("%d%c",ans[i],"\n "[i<m]);
if(res)printf("Unhappy! %d\n",res);
exit(0);
}
vector<array<int,3>>s={
{2,3,4},
{5,1,6},
{7,8,9},
{2,5,7},
{3,1,8},
{4,6,9},
{2,1,9},
{4,1,7}
};
void run(){
// cerr<<"run"<<endl;
bool flag=0,tag=0;
for(int x=1;x<=9;x++){
auto [i,j]=pos[x];
if(val[i][j]!=-1)continue;
if(n>0){
tag=1;
int y=a[++cur];
n--;
val[i][j]=y;
if(y==t)get(1);
if(!y){
get(1);
val[i][j]=-1,insert(y);
// cerr<<n<<endl;
return;
}
}
}
// cerr<<"run"<<' '<<x<<' '<<val[1][1]<<endl;
if([&](){
vector<int>p;
for(int i:{0,1,2})for(int j:{0,1,2}){
if(val[i][j]==-1)return 0;
p.push_back(val[i][j]);
}
sort(all(p));
for(int i=1;i<p.size();i++){
if(p[i]==p[i-1])return 0;
}
return 1;
}()){
tag=1;
auto [i,j]=pos[1];
insert(val[i][j]);
val[i][j]=-1;
return;
}
for(auto &id:s){
vector<int>t;
for(auto p:id){
auto [i,j]=pos[p];
t.push_back(val[i][j]);
}
sort(all(t));
if(t[0]==-1||t[0]!=t[1]||t[1]!=t[2])continue;
tag=1;
for(auto p:id){
if(p==1){
flag=1;
continue;
}
auto [i,j]=pos[p];
insert(val[i][j]);
val[i][j]=-1;
}
get(5);
}
for(int i=1;i<=9;i++){
auto [ax,ay]=pos[i];
if(val[ax][ay]==-1)continue;
for(int j=i+1;j<=9;j++){
auto [bx,by]=pos[j];
if(val[ax][ay]!=val[bx][by])continue;
tag=1;
if(i==1){
insert(val[bx][by]);
val[bx][by]=-1;
get(1);
flag=1;
continue;
}
insert(val[ax][ay]);
insert(val[bx][by]);
val[ax][ay]=val[bx][by]=-1;
get(1);
}
}
// cerr<<"flag\n";
if(flag){
tag=1;
insert(val[1][1]);
val[1][1]=-1;
}
if(!tag){
for(int i:{0,1,2})for(int j:{0,1,2}){
if(val[i][j]!=-1){
insert(val[i][j]);
val[i][j]=-1;
}
}
end();
}else if([&](){
for(int i:{0,1,2})for(int j:{0,1,2}){
if(val[i][j]!=-1)return 0;
}
return 1;
}()){
get(10);
}
}
int main(){
freopen(".in","r",stdin);
for(auto &x:s)sort(all(x));
sort(all(s));
// for(auto &x:s)cerr<<x[0]<<' '<<x[1]<<' '<<x[2]<<endl;
for(int i:{0,1,2})for(int j:{0,1,2}){
pos[id[i][j]]={i,j},val[i][j]=-1;
}
scanf("%d%d%d%d",&n,&m,&k,&t);
int las=n;
n=0,get(las);
for(int i=1;i<=k;i++)scanf("%d",&a[i]);
for(;;)run();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3868kb
input:
I love Liaoning. Love Dalian! 1 love
output:
0
result:
wrong answer 1st lines differ - expected: '3', found: '0'