QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#542169#8935. Puzzle: Easy as Scrabbleucup-team180#WA 1ms3596kbC++203.0kb2024-08-31 23:09:272024-08-31 23:09:28

Judging History

你现在查看的是最新测评结果

  • [2024-08-31 23:09:28]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3596kb
  • [2024-08-31 23:09:27]
  • 提交

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;
	}
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3596kb

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: 3508kb

input:

1 2
....
Nx..
..O.

output:

NO

result:

ok Correct.

Test #3:

score: -100
Wrong Answer
time: 0ms
memory: 3456kb

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.