QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#540107#8935. Puzzle: Easy as Scrabbleucup-team159#WA 0ms3780kbC++234.7kb2024-08-31 16:26:502024-08-31 16:26:50

Judging History

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

  • [2024-08-31 16:26:50]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3780kb
  • [2024-08-31 16:26:50]
  • 提交

answer

#line 1 "D.cpp"
// #pragma GCC target("avx2,avx512f,avx512vl,avx512bw,avx512dq,avx512cd,avx512vbmi,avx512vbmi2,avx512vpopcntdq,avx512bitalg,bmi,bmi2,lzcnt,popcnt")
// #pragma GCC optimize("Ofast")

#line 2 "/home/sigma/comp/library/template.hpp"

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using uint = unsigned int;
using ull = unsigned long long;
#define rep(i,n) for(int i=0;i<int(n);i++)
#define rep1(i,n) for(int i=1;i<=int(n);i++)
#define per(i,n) for(int i=int(n)-1;i>=0;i--)
#define per1(i,n) for(int i=int(n);i>0;i--)
#define all(c) c.begin(),c.end()
#define si(x) int(x.size())
#define pb push_back
#define eb emplace_back
#define fs first
#define sc second
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
template<class T,class U> bool chmax(T& x, U y){
	if(x<y){ x=y; return true; }
	return false;
}
template<class T,class U> bool chmin(T& x, U y){
	if(y<x){ x=y; return true; }
	return false;
}
template<class T> void mkuni(V<T>& v){sort(all(v));v.erase(unique(all(v)),v.end());}
template<class T> int lwb(const V<T>& v, const T& a){return lower_bound(all(v),a) - v.begin();}
template<class T>
V<T> Vec(size_t a) {
    return V<T>(a);
}
template<class T, class... Ts>
auto Vec(size_t a, Ts... ts) {
  return V<decltype(Vec<T>(ts...))>(a, Vec<T>(ts...));
}
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

#ifdef LOCAL
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
void dmpr(ostream& os){os<<endl;}
template<class T,class... Args>
void dmpr(ostream&os,const T&t,const Args&... args){
	os<<t<<" ~ ";
	dmpr(os,args...);
}
#define shows(...) cerr << "LINE" << __LINE__ << " : ";dmpr(cerr,##__VA_ARGS__)
#define dump(x) cerr << "LINE" << __LINE__ << " : " << #x << " = {";  \
	for(auto v: x) cerr << v << ","; cerr << "}" << endl;
#else
#define show(x) void(0)
#define dump(x) void(0)
#define shows(...) void(0)
#endif

template<class D> D divFloor(D a, D b){
	return a / b - (((a ^ b) < 0 && a % b != 0) ? 1 : 0);
}
template<class D> D divCeil(D a, D b) {
	return a / b + (((a ^ b) > 0 && a % b != 0) ? 1 : 0);
}
#line 5 "D.cpp"

void showf(V<string> s){
	rep(i,si(s)){
		cout << s[i] << endl;
	}
	cout << endl;
}

// 書き込む値, 条件
bool match(char c, char tar){
	if(tar == '.') return true;
	return c == tar;
}

void rot(V<string>& s){
	int H = si(s), W = si(s[0]);
	V<string> t(W, string(H,'.'));
	rep(i,H) rep(j,W) t[j][H-1-i] = s[i][j];
	s = t;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);		//DON'T USE scanf/printf/puts !!
	cout << fixed << setprecision(20);

	int H,W; cin >> H >> W;
	V<string> s(H+2); rep(i,H+2) cin >> s[i];
	V<string> in = s;

	auto Write = [&](int i, int j, char c){
		s[i][j] = c;
	};

	rep1(i,H){
		int l = 1, r = W;	// up,down のためにfree で使える区間 [l,r]
		// left
		if(s[i][0] != '.'){
			char tar = s[i][0];
			rep1(j,W){
				if(s[i][j] == 'x') continue;
				if(s[i][j] != '.'){
					if(!match(s[i][j], tar)) goto no;
					if(!match(s[i][j],s[0][j])) goto no;
					// ok
					l = j+1;
					break;
				}
				if(match(tar,s[0][j])){
					Write(i,j,tar);
					s[i][0] = '.';
					s[0][j] = '.';
					l = j+1;
					break;
				}
			}
			if(l == 1) goto no;
		}
		if(s[i][W+1] != '.'){
			char tar = s[i][W+1];
			per1(j,W){
				if(s[i][j] == 'x') continue;
				if(s[i][j] != '.'){
					if(!match(s[i][j], tar)) goto no;
					if(!match(s[i][j],s[0][j])) goto no;
					// ok
					r = j-1;
					break;
				}
				if(match(tar,s[0][j])){
					Write(i,j,tar);
					s[i][W+1] = '.';
					s[0][j] = '.';
					r = j-1;
					break;
				}
			}
			if(r == W) goto no;
		}
		for(int j=l;j<=r;j++){
			if(s[i][j] == 'x') continue;
			assert(s[i][j] == '.');
			if(s[0][j] != '.'){
				// up
				Write(i,j,s[0][j]);
				s[0][j] = '.';
			}else{
				// down
				Write(i,j,s[H+1][j]);
				// より下に書き込むかもしれないのでまだ条件はわからない
			}
		}
	}
	rep1(i,H) rep1(j,W) if(s[i][j] == 'x') s[i][j] = '.';

	rep(ph,4){
		// showf(s); showf(in);
		rep1(i,H) if(in[i][0] != '.'){
			bool ok = false;
			rep1(j,W) if(s[i][j] != '.'){
				if(s[i][j] != in[i][0]) goto no;
				ok = true; break;
			}
			if(!ok) goto no;
		}
		rot(s); rot(in); swap(H,W);
	}
	cout << "YES" << endl;
	rep1(i,H){
		rep1(j,W) cout << s[i][j];
		cout << endl;
	}
	return 0;

	no:
	cout << "NO" << endl;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
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: 3780kb

input:

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

output:

NO

result:

ok Correct.

Test #3:

score: 0
Accepted
time: 0ms
memory: 3528kb

input:

5 5
.U.N.X.
U....xX
Ox....X
M...xxN
Vx....S
Ix.x..X
..IBHX.

output:

YES
UINX.
.OBHX
MIN..
.VBHS
.I.HX

result:

ok Correct.

Test #4:

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

input:

10 10
.BAZEMIEKUJ.
A..........K
B..x.x.x..x.
K.........xT
A.x..x.....J
Hx....x....B
Q..x....x.xW
S...x......W
S...x.xxx..Z
...x......xZ
I..x..x.x.xR
.QKO.ID..RW.

output:

NO

result:

wrong answer Jury has answer but participant has not.