QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#542181 | #8935. Puzzle: Easy as Scrabble | ucup-team180# | WA | 0ms | 3656kb | C++20 | 3.7kb | 2024-08-31 23:15:56 | 2024-08-31 23:15:56 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define pll piar<ll,ll>
#define vi vector<int>
#define vl vector<ll>
#define ov3(a,b,c,name,...)name
#define rep0(n) for(ll aaaaa = 0; aaaaa < n;++aaaaa)
#define rep1(i,n) for(ll i = 0;i < (n); i++)
#define rep2(i,a,b) for(ll i = (a); i <(b); i ++)
#define rep(...) ov3(__VA_ARGS__, rep2,rep1,rep0)(__VA_ARGS__)
#define fore(e,v) for(auto &&e:v)
#define all(a) begin(a),end(a)
#define si(a) (int)(size(a))
bool chmin(auto &a, auto b){return a>b?a = b,1:0;}
bool chmax(auto &a, auto b){return a<b?a = b,1:0;}
#define pb push_back
#define eb emplace_back
#define i128 __int128_t
#define per(i,n) for(int i = n-1;i >= 0;i--)
ll vis[1010][1010];
int main(){
cin.tie(0) -> sync_with_stdio(0);
ll n,m;
cin>>n>>m;
vector<string> s(n + 2);
rep(i,n + 2){
cin>>s[i];
}
rep(i,n + 2)rep(j,m + 2){
if(i == 0 || i == n + 1 || j == 0 || j == m + 1){
if(not(s[i][j] == '.' || s[i][j] =='A' || s[i][j] == 'B' || s[i][j] == 'C')){
cout<<"NO"<<endl;
return 0;
}
}
}
vector<string> t = s;
rep(i,n + 2)rep(j, m + 2)t[i][j] = '.';
vl u(m + 2, 1),l(n + 2, 1),d(m + 2, n),r(n + 2,m);
rep(i,n + 2)rep(j,m + 2)vis[i][j] = 0;
queue<pair<ll,ll> > que;
auto test = [&](ll i,ll j){
if(not(1 <= i && i <= n && 1 <= j && j <=m))return;
if(t[i][j] == 'x')return;
if(vis[i][j])return;
set<char> st;
if(u[j] == i)st.insert(s[0][j]);
if(d[j] == i)st.insert(s[n + 1][j]);
if(l[i] == j)st.insert(s[i][0]);
if(r[i] == j)st.insert(s[i][m + 1]);
st.erase('.');
if(si(st) >= 2){
que.push({i,j});
vis[i][j] = 1;
}
};
auto makex = [&](ll i,ll j){
t[i][j] = 'x';
while(t[u[j]][j] == 'x')u[j]++; test(u[j],j);
while(t[d[j]][j] == 'x')d[j]--; test(d[j],j);
while(t[i][l[i]] == 'x')l[i]++; test(i,l[i]);
while(t[i][r[i]] == 'x')r[i]--; test(i,r[i]);
};
for(ll i =1;i <= n;i++)for(ll j = 1;j <= m;j++){
if(s[i][j] == 'x'){
que.push({i,j});
}
else{
test(i,j);
}
}
while(!que.empty()){
auto [i,j] = que.front();
que.pop();
makex(i,j);
}
// cout<<"t = "<<endl;
// for(ll i = 1;i <= n;i++){
// for(ll j = 1;j <= m;j++){
// cout<<t[i][j];
// }
// cout<<endl;
// }
for(ll i = 1;i <= n;i++)if(s[i][0] != '.'){
if(l[i] > m){
cout<<"NO"<<endl;
return 0;
}
t[i][l[i]] = s[i][0];
}
for(ll i = 1;i <= n;i++)if(s[i][m + 1] != '.'){
if(r[i] < 1){
cout<<"NO"<<endl;
return 0;
}
t[i][r[i]] = s[i][m + 1];
}
for(ll j = 1;j <= m;j++)if(s[0][j] != '.'){
if(u[j] > n){
cout<<"NO"<<endl;
return 0;
}
t[u[j]][j] = s[0][j];
}
for(ll j = 1;j <= m;j++)if(s[n + 1][j] != '.'){
if(u[j] < 1){
cout<<"NO"<<endl;
return 0;
}
t[u[j]][j] = s[n + 1][j];
}
cout<<"YES"<<endl;
for(ll i = 1;i <= n;i++){
for(ll j = 1;j <= m;j++){
if(t[i][j] == 'x')t[i][j] = '.';
cout<<t[i][j];
}
cout<<endl;
}
for(ll i = 1;i <= n;i++)if(s[i][0] != '.'){
char f = 'n';
for(ll j = 1;j <= m;j++){
if(t[i][j] != '.'){
f = t[i][j];
break;
}
}
assert(s[i][0] == f);
}
for(ll i = 1;i <= n;i++)if(s[i][m + 1] != '.'){
char f = 'n';
for(ll j = m;j >= 1;j--){
if(t[i][j] != '.'){
f = t[i][j];
break;
}
}
assert(s[i][m + 1] == f);
}
for(ll j = 1;j <= m;j++)if(s[0][j] != '.'){
char f = 'n';
for(ll i = 1;i <= n;i++){
if(t[i][j] != '.'){
f = t[i][j];
break;
}
}
assert(s[0][j] == f);
}
for(ll j = 1;j <= m;j++)if(s[n + 1][j] != '.'){
char f = 'n';
for(ll i = n;i >= 1;i--){
if(t[i][j] != '.'){
f = t[i][j];
break;
}
}
assert(s[n + 1][j] == f);
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3656kb
input:
5 5 .CBA... ....x.. ..x...C A.....B B..x..A C...... .......
output:
YES CBA.. ....C A...B B...A C....
result:
ok Correct.
Test #2:
score: 0
Accepted
time: 0ms
memory: 3600kb
input:
1 2 .... Nx.. ..O.
output:
NO
result:
ok Correct.
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 3652kb
input:
5 5 .U.N.X. U....xX Ox....X M...xxN Vx....S Ix.x..X ..IBHX.
output:
NO
result:
wrong answer Jury has answer but participant has not.