QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#236130 | #6398. Puzzle: Tapa | kai_wei# | WA | 0ms | 3900kb | C++20 | 4.5kb | 2023-11-03 16:53:32 | 2023-11-03 16:53:33 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N = 55;
char a[500][500];
char b[500][500];
struct node{
int to;
};
struct eg{
int x,y;
};
map<int,eg>mp;
vector<node>e[1050];
int main()
{
int n,m;
cin>>n>>m;
int fg=0;
for(int i=1;i<=2*n-1;i++)
{
for(int j=1;j<=2*m-1;j++)
{
cin>>a[i][j];
b[i][j]=a[i][j];
if(a[i][j]=='.')
{
a[i][j]='#';
}
if(a[i][j]=='7')
{
fg=1;
}
if(isdigit(a[i][j])&&a[i][j]>='4')
{
a[i][j]-=2;
}
}
}
if(fg)
{
cout<<"NO"<<endl;
return 0;
}
int prev=0;
int cnt=0;
for(int i=1;i<=2*m-1;i++)
{
if(!isdigit(a[1][i]))
{
continue;
}
if(prev==0)
{
cnt++;
prev=cnt;
mp[cnt]={1,i};
}else
{
++cnt;
//中间的可以用 []/2
e[cnt].push_back({prev});
mp[cnt]={1,i};
prev=cnt;
}
}
for(int i=2;i<=2*n-1;i++)
{
if(!isdigit(a[i][2*m-1]))
{
continue;
}
++cnt;
//中间的可以用 []/2
e[cnt].push_back({prev});
mp[cnt]={i,2*m-1};
prev=cnt;
}
for(int i=2*m-2;i>=1;i--)
{
if(!isdigit(a[2*n-1][i]))
{
continue;
}
++cnt;
//中间的可以用 []/2
e[cnt].push_back({prev});
mp[cnt]={2*n-1,i};
prev=cnt;
}
for(int i=2*n-2;i>=1;i--)
{
if(!isdigit(a[i][1]))
{
continue;
}
++cnt;
if(i==1)
{
e[1].push_back({prev});
cnt--;
break;
}
//中间的可以用 []/2
e[cnt].push_back({prev});
mp[cnt]={i,1};
prev=cnt;
}
int st=0;
for(int i=1;i<=cnt;i++)
{
//得到3然后往下一个走
if(a[mp[i].x][mp[i].y]=='3')
{
st=i;
break;
}
}
if(st==0)
{
int f=0;
for(int i=1;i<=cnt;i++)
{
int last=e[i][0].to;
int xx=(mp[i].x+mp[last].x)/2;
int yy=(mp[i].y+mp[last].y)/2;
if(f)
{
a[xx][yy]='.';
}else
{
a[xx][yy]='#';
}
f^=1;
}
cout<<"YES"<<endl;
for(int i=1;i<=2*n-1;i++)
{
for(int j=1;j<=(2*m-1);j++)
{
if(isdigit(a[i][j]))
{
cout<<b[i][j];
}else
{
cout<<a[i][j];
}
}
cout<<endl;
}
}else
{
int f=0;
int fg=0;
vector<int>vis(cnt+5);
for(int i=st;;i=e[i][0].to)
{
if(vis[i])
{
break;
}
vis[i]=1;
//对象
int last=e[i][0].to;
int xx=(mp[i].x+mp[last].x)/2;
int yy=(mp[i].y+mp[last].y)/2;
//若f=1 用#
if(a[mp[last].x][mp[last].y]=='2')
{
//2
if(f)
{
a[xx][yy]='.';
}else
{
a[xx][yy]='#';
}
f^=1;
}else
{
if(f)
{
//不行!
fg=1;
break;
}else
{
a[xx][yy]='#';
//并且f要保持不变
}
}
}
if(fg)
{
cout<<"NO"<<endl;
return 0;
}
cout<<"YES"<<endl;
for(int i=1;i<=2*n-1;i++)
{
for(int j=1;j<=(2*m-1);j++)
{
if(isdigit(a[i][j]))
{
cout<<b[i][j];
}else
{
cout<<a[i][j];
}
}
cout<<endl;
}
}
}
/*
3 3
3.5.3
.....
4.8.5
.....
2.4.2
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3536kb
input:
3 3 2.4.3 ..... 5.8.5 ..... 3.5.3
output:
YES 2.4#3 ##### 5#8#5 ##### 3#5#3
result:
ok Correct.
Test #2:
score: 0
Accepted
time: 0ms
memory: 3500kb
input:
3 3 3.4.3 ..... 5.7.5 ..... 3.5.3
output:
NO
result:
ok Correct.
Test #3:
score: 0
Accepted
time: 0ms
memory: 3616kb
input:
2 2 2.2 ... 2.2
output:
YES 2.2 ### 2.2
result:
ok Correct.
Test #4:
score: 0
Accepted
time: 0ms
memory: 3548kb
input:
2 50 2.4.4.4.4.5.5.5.5.5.5.5.5.4.5.5.4.4.5.5.5.5.4.5.5.5.5.5.4.4.5.4.5.5.5.5.5.5.5.5.5.5.5.4.4.5.5.4.5.3 ................................................................................................... 2.5.5.4.4.5.5.5.4.4.5.5.5.4.5.5.5.5.5.5.5.5.4.4.4.5.5.5.5.5.5.4.4.4.5.5.5.5.5.5.5.4.4.5.5.5.5.4...
output:
NO
result:
ok Correct.
Test #5:
score: 0
Accepted
time: 0ms
memory: 3648kb
input:
2 50 2.4.4.5.5.5.5.5.5.5.5.5.4.4.5.5.5.5.4.4.5.5.4.4.5.5.5.4.5.4.4.4.5.4.4.5.4.4.5.5.5.5.4.4.5.5.5.5.5.2 ................................................................................................... 3.5.4.5.5.5.5.5.5.5.5.5.5.5.4.5.5.5.5.4.5.5.5.5.4.4.5.4.5.4.5.5.5.5.5.4.4.5.5.5.4.4.5.5.5.5.5.4...
output:
NO
result:
ok Correct.
Test #6:
score: 0
Accepted
time: 0ms
memory: 3740kb
input:
50 2 3.2 ... 5.4 ... 5.5 ... 4.4 ... 5.5 ... 5.5 ... 5.5 ... 5.5 ... 5.5 ... 5.5 ... 5.5 ... 5.4 ... 5.4 ... 5.5 ... 5.5 ... 5.5 ... 5.5 ... 5.5 ... 5.4 ... 5.4 ... 5.4 ... 5.4 ... 4.4 ... 5.5 ... 5.5 ... 4.4 ... 5.4 ... 5.4 ... 5.5 ... 4.5 ... 4.5 ... 5.5 ... 5.5 ... 5.5 ... 5.5 ... 5.5 ... 5.5 ......
output:
NO
result:
ok Correct.
Test #7:
score: 0
Accepted
time: 0ms
memory: 3900kb
input:
50 2 3.3 ... 5.4 ... 5.4 ... 5.4 ... 5.4 ... 5.5 ... 4.4 ... 4.4 ... 5.5 ... 4.4 ... 5.5 ... 5.5 ... 5.5 ... 5.5 ... 4.5 ... 5.5 ... 5.5 ... 5.4 ... 5.4 ... 5.5 ... 5.4 ... 5.5 ... 5.4 ... 5.4 ... 5.5 ... 5.5 ... 4.5 ... 4.5 ... 4.5 ... 4.5 ... 5.5 ... 5.4 ... 5.4 ... 5.5 ... 5.5 ... 4.4 ... 4.4 ......
output:
NO
result:
ok Correct.
Test #8:
score: -100
Wrong Answer
time: 0ms
memory: 3612kb
input:
3 50 3.5.5.5.5.5.5.5.5.5.5.5.5.5.5.5.5.5.5.5.5.5.5.4.4.5.5.5.5.4.4.5.5.5.5.5.5.5.5.4.4.5.5.4.4.5.4.4.5.3 ................................................................................................... 4.8.8.8.8.8.8.8.8.8.8.8.8.8.8.7.7.7.7.7.7.8.8.8.8.8.8.8.8.8.8.8.8.8.8.8.8.8.8.8.8.8.8.8.8.7.7.8...
output:
NO
result:
wrong answer Jury has answer but participant has not.