QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#236094 | #6398. Puzzle: Tapa | TimMCBen# | RE | 1ms | 3524kb | C++20 | 4.8kb | 2023-11-03 16:21:43 | 2023-11-03 16:21:43 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N = 55;
char a[N][N];
char b[N][N];
struct node{
int to;
};
struct eg{
int x,y;
};
map<int,eg>mp;
vector<node>e[N];
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;
}
/* for(int i=1;i<=2*n-1;i++)
{
for(int j=1;j<=2*m-1;j++)
{
cout<<a[i][j];
b[i][j]=a[i][j];
}
cout<<endl;
} */
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;
}
/* for(int i=1;i<=cnt;i++)
{
cout<<i<<" "<<mp[i].x<<" "<<mp[i].y<<endl;
int last=e[i][0].to;
cout<<e[i][0].to<<"-"<<(mp[i].x+mp[last].x)/2<<" "<<(mp[i].y+mp[last].y)/2<<endl;
} */
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;
for(int i=st;((i+cnt-1-1)%cnt+1)!=st;i=(i+cnt-1-1)%cnt+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
2.4.2
.....
4.8.4
.....
2.4.2
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3336kb
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: 3408kb
input:
3 3 3.4.3 ..... 5.7.5 ..... 3.5.3
output:
NO
result:
ok Correct.
Test #3:
score: 0
Accepted
time: 1ms
memory: 3524kb
input:
2 2 2.2 ... 2.2
output:
YES 2.2 ### 2.2
result:
ok Correct.
Test #4:
score: -100
Runtime Error
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...