QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#848627 | #9926. Flipping Paths | isWFnoya# | RE | 0ms | 4036kb | C++23 | 3.2kb | 2025-01-08 23:07:24 | 2025-01-08 23:07:24 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=2e6+10;
typedef long long ll;
typedef pair<ll,ll> PII;
int n,m,k;
// ll a[N],b[N],c[N],dep[N];
// char s[N];
int a[314][314],b[314][314];
string s;
vector<int> ans[410];
int idx;
bool check(){
idx=0;
vector<PII> now;
for(int j=m-1;j>=0;j--){
if(a[0][j]==1){
idx++;
ans[idx].push_back(0);
ans[idx].push_back(j);
for(int i=0;i<=j;i++) a[0][i]^=1;
now.push_back({j,idx});
}
}
for(int i=1;i<n-1;i++){
// cout<<i<<endl;
for(auto [x,y]:now){
a[i][x]^=1;
}
sort(now.begin(),now.end(),greater<PII>());
int p=0;
vector<PII> nw;
for(int j=m-1;j>0;j--){
if(a[i][j]==0) continue;
while(p<now.size()&&now[p].first>=j){
nw.push_back(now[p]);
ans[now[p].second].push_back(now[p].first);
p++;
}
if(p>=now.size()){
idx++;
for(int k=0;k<=i;k++) ans[idx].push_back(0);
now.push_back({0,idx});
idx++;
for(int k=0;k<=i;k++) ans[idx].push_back(0);
now.push_back({0,idx});
}
for(int k=now[p].first+1;k<=j;k++) a[i][k]^=1;
now[p].first=j;
ans[now[p].second].push_back(j);
nw.push_back(now[p]);
}
if(a[i][0]) return false;
while(p<now.size()){
nw.push_back(now[p]);
ans[now[p].second].push_back(now[p].first);
p++;
}
now=nw;
nw.clear();
}
for(auto [x,y]:now){
for(int i=x;i<m;i++) a[n-1][i]^=1;
ans[y].push_back(m-1);
}
for(int i=0;i<n;i++){
for(int j=0;j<m;j++) if(a[i][j]) return false;
}
puts("YES");
printf("%d\n",idx);
// for(auto x:ans[1]) cout<<x<<" ";
// cout<<endl;
assert(idx<=400);
for(int i=1;i<=idx;i++){
string s;
for(int j=1;j<ans[i].size();j++){
// ans[i][j]=0;
for(int c=ans[i][j-1];c<ans[i][j];c++) s+="R";
if(j!=ans[i].size()-1)
s+="D";
// printf("D");
}
cout<<s<<"\n";
assert(s.size()==n+m-2);
// printf("\n");
}
return true;
}
void __(){
cin>>n>>m;
for(int i=0;i<n;i++){
cin>>s;
// cout<<s<<endl;
for(int j=0;j<m;j++){
if(s[j]=='W') b[i][j]=0;
else b[i][j]=1;
}
}
for(int i=0;i<n;i++){
for(int j=0;j<m;j++) a[i][j]=b[i][j];
}
for(int i=0;i<=400;i++) ans[i].clear();
if(check()) return;
for(int i=0;i<n;i++){
for(int j=0;j<m;j++) b[i][j]^=1;
}
for(int i=0;i<n;i++){
for(int j=0;j<m;j++) a[i][j]=b[i][j];
}
for(int i=0;i<=400;i++) ans[i].clear();
if(check()) return;
puts("NO");
}
//2*1 1*2
//2 2 2
int main(){
// dfs(0);
// cout<<able.size()<<endl;
int _=1;
cin>>_;
while(_--){
__();
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 4036kb
input:
4 3 3 WBB BWB BBW 1 5 WWWWW 2 2 BB BB 4 1 W B B W
output:
YES 2 RRDD DDRR YES 0 YES 0 NO
result:
ok ok (4 test cases)
Test #2:
score: -100
Runtime Error
input:
323 1 2 BB 1 2 BW 1 2 WB 1 2 WW 2 1 B B 2 1 B W 2 1 W B 2 1 W W 1 3 BBB 1 3 BBW 1 3 BWB 1 3 BWW 1 3 WBB 1 3 WBW 1 3 WWB 1 3 WWW 2 2 BB BB 2 2 BB BW 2 2 BB WB 2 2 BB WW 2 2 BW BB 2 2 BW BW 2 2 BW WB 2 2 BW WW 2 2 WB BB 2 2 WB BW 2 2 WB WB 2 2 WB WW 2 2 WW BB 2 2 WW BW 2 2 WW WB 2 2 WW WW 3 1 B B B 3 ...
output:
YES 0 NO NO YES 0 YES 1 D NO NO YES 0 YES 0 NO NO NO NO NO NO YES 0 YES 0 NO YES 1 RD NO YES 1 DR NO YES 2 RD DR NO NO YES 2 RD DR NO YES 1 DR NO YES 1 RD NO YES 0 YES 1 DD NO NO NO NO NO NO YES 0 YES 0 NO NO NO NO NO NO NO NO NO NO NO NO NO NO YES 0 YES 0 NO NO NO NO NO YES 1 RRD NO NO NO YES 2 RRD...