QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#241722 | #6398. Puzzle: Tapa | ucup-team902# | WA | 1ms | 4008kb | C++14 | 2.9kb | 2023-11-06 16:22:39 | 2023-11-06 16:22:39 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define cs const
#define re register
#define pb push_back
#define pii pair<int,int>
#define ll long long
#define y1 shinkle
#define fi first
#define se second
#define bg begin
namespace IO{
#define gc getchar
inline int read(){
char ch=gc();
int res=0;bool f=1;
while(!isdigit(ch))f^=ch=='-',ch=gc();
while(isdigit(ch))res=(res*10)+(ch^48),ch=gc();
return f?res:-res;
}
inline ll readll(){
char ch=gc();
ll res=0;bool f=1;
while(!isdigit(ch))f^=ch=='-',ch=gc();
while(isdigit(ch))res=(res*10)+(ch^48),ch=gc();
return f?res:-res;
}
inline char readchar(){
char ch=gc();
while(isspace(ch))ch=gc();
return ch;
}
inline int readstring(char *s){
int top=0;char ch=gc();
while(isspace(ch))ch=gc();
while(!isspace(ch)&&ch!=EOF)s[++top]=ch,ch=gc();
s[top+1]='\0';return top;
}
}
using IO::read;
using IO::readll;
using IO::readchar;
using IO::readstring;
template<typename tp>inline void chemx(tp &a,tp b){(a<b)?(a=b):0;}
template<typename tp>inline void chemn(tp &a,tp b){(a>b)?(a=b):0;}
cs int N=105,M=N*N;
char s[N][N];
int a[M];
int n,m,cnt;
int id[N][N];
pii p[M];
vector<int> e[M];
int vis[M],mat[M];
void add(int u,int v){
if(a[u]==1||a[v]==1)return;
if(u&1)e[u].pb(v);
else e[v].pb(u);
}
bool dfs(int u){
if(vis[u])return false;
vis[u]=1;
for(int v:e[u]){
if(!mat[v]||dfs(mat[v])){
mat[v]=u;return true;
}
}
return false;
}
int main(){
n=read(),m=read();
for(int i=1;i<=2*n-1;i++){
readstring(s[i]);
if(i&1){
for(int j=2;j<=2*m-1;j+=2)s[i][j]='#';
for(int j=1;j<=2*m-1;j+=2){
//a[(i+1)/2][(j+1)/2]=s[i]-'0';
id[(i+1)/2][(j+1)/2]=++cnt;
a[cnt]=s[i][j]-'0';
if(a[cnt]<=3)a[cnt]-=2;
else if(a[cnt]<=5)a[cnt]-=4;
else if(a[cnt]<=8)a[cnt]-=7;
p[cnt]=pii(i,j);
}
}
else{
for(int j=1;j<=2*m-1;j++)s[i][j]='#';
}
}
// puts("");
// for(int i=1;i<=2*n-1;i++){
// cout<<(s[i]+1)<<'\n';
// }puts("");
for(int i=1;i<m;i++){
add(id[1][i],id[1][i+1]);
add(id[n][i],id[n][i+1]);
}
for(int i=1;i<n;i++){
add(id[i][1],id[i+1][1]);
add(id[i][m],id[i+1][m]);
}
for(int i=2;i<n;i++)
for(int j=2;j+1<m;j++){
add(id[i][j],id[i][j+1]);
}
for(int i=2;i+1<n;i++)
for(int j=2;j<m;j++){
add(id[i][j],id[i+1][j]);
}
for(int i=1;i<=cnt;i++)if(a[i]==0&&(i&1)){
memset(vis,0,sizeof(vis));
if(!(dfs(i))){
puts("NO");exit(0);
}
}
for(int i=1;i<=cnt;i++)if(a[i]==0&&(i%2==0)){
if(!mat[i]){
puts("NO");exit(0);
}
int px=p[i].fi+p[mat[i]].fi;
int py=p[i].se+p[mat[i]].se;
assert(px%2==0&&py%2==0);
s[px/2][py/2]='.';
}
for(int i=1;i<=2*n-1;i+=2)
for(int j=1;j<=2*m-1;j+=2){
int ct=0;
for(int t=-1;t<=1;t++)
for(int r=-1;r<=1;r++)if(t!=0||r!=0){
ct+=(s[i+t][j+r]=='#');
}
assert(ct==s[i][j]-'0');
}
puts("YES");
for(int i=1;i<=2*n-1;i++){
cout<<(s[i]+1)<<'\n';
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3924kb
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: 3856kb
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: 3948kb
input:
2 2 2.2 ... 2.2
output:
YES 2.2 ### 2.2
result:
ok Correct.
Test #4:
score: 0
Accepted
time: 0ms
memory: 3928kb
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: 3936kb
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: 3896kb
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: 3952kb
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: 4008kb
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.