QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#87094#5240. Łamigłówka [C]anhduc27010 21ms7576kbC++234.2kb2023-03-11 17:14:162023-03-11 17:14:19

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-11 17:14:19]
  • 评测
  • 测评结果:0
  • 用时:21ms
  • 内存:7576kb
  • [2023-03-11 17:14:16]
  • 提交

answer

/*
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
*/
#include<bits/stdc++.h>
using namespace std;
#define all(x) x.begin(), x.end()
#define len(x) ll(x.size())
#define eb emplace_back
#define PI 3.14159265359
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define MIN(v) *min_element(all(v))
#define MAX(v) *max_element(all(v))
#define BIT(x,i) (1&((x)>>(i)))
#define MASK(x) (1LL<<(x))
#define task "tnc"  
typedef long long ll;
const ll INF=1e18;
const int maxn=1e6+5;
const int mod=1e9+7;
const int mo=998244353;
using pi=pair<ll,ll>;
using vi=vector<ll>;
using pii=pair<pair<ll,ll>,ll>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int n,m;
int k[505][505];
int id[maxn];
int vis[maxn];
int perm[maxn];
signed main()
{
	cin.tie(0),cout.tie(0)->sync_with_stdio(0);
    //freopen(task".inp" , "r" , stdin);
    //freopen(task".out" , "w" , stdout);
    cin>>n>>m;
    for(int i=1;i<=n;i++){
    	for(int j=1;j<=m;j++){
    		char x;
    		cin>>x;
    		if(x=='B')k[i][j]=1;
    		else if(x=='C')k[i][j]=2;
    	}
    }
    int q;
    cin>>q;
    string p;
    cin>>p;
    vector<char>s;
    for(auto c:p){
    	if(s.empty())s.pb(c);
    	else if(c==s.back() || c+s.back()=='D'+'G' || c+s.back()=='L'+'P'){
    		if(s.size()>3 && s[s.size()-3]==c)s.pop_back();
    		else s.back()=c;
    	}
    	else if(s.size()>=2 && c==s[s.size()-2])continue;
    	else{
    		s.pb(c);
    	}
    }
    for(int i=0;i<min(s.size(),4+(s.size()%4));i++){
    	char c=s[i];
    	if(c=='L'){
    		for(int j=1;j<=n;j++){
    			int tmp=1;
    			for(int z=1;z<=m;z++){
    				if(k[j][z]){
    					swap(k[j][z],k[j][tmp++]);
    				}
    			}
    		}
    	}
    	if(c=='P'){
    		for(int j=1;j<=n;j++){
    			int tmp=m;
    			for(int z=m;z>=1;z--){

    				if(k[j][z]){
    					swap(k[j][z],k[j][tmp--]);

    				}
    			}
    		}
    	}
    	if(c=='G'){
    		for(int j=1;j<=m;j++){
    			int tmp=1;
    			for(int z=1;z<=n;z++){
    				if(k[z][j]){
    					swap(k[tmp++][j],k[z][j]);
    				}
    			}
    		}
    	}
    	if(c=='D'){
    		for(int j=1;j<=m;j++){
    			int tmp=n;
    			for(int z=n;z>=1;z--){
    				if(k[z][j]){
    					swap(k[tmp--][j],k[z][j]);
    				}
    			}
    		}
    	}
    }
    if(s.size()>=4){
    	int tmp1=1;
    	for(int i=1;i<=n;i++){
    		for(int j=1;j<=m;j++){
    			if(k[i][j]){
    				id[tmp1]=k[i][j];
    				k[i][j]=tmp1;
    				tmp1++;
    			}
    		}
    	}
    	for(int i=s.size()-4;i<s.size();i++){
	    	char c=s[i];
    	if(c=='L'){
    		for(int j=1;j<=n;j++){
    			int tmp=1;
    			for(int z=1;z<=m;z++){
    				if(k[j][z]){
    					swap(k[j][z],k[j][tmp++]);
    				}
    			}
    		}
    	}
    	if(c=='P'){
    		for(int j=1;j<=n;j++){
    			int tmp=m;
    			for(int z=m;z>=1;z--){

    				if(k[j][z]){
    					swap(k[j][z],k[j][tmp--]);

    				}
    			}
    		}
    	}
    	if(c=='G'){
    		for(int j=1;j<=m;j++){
    			int tmp=1;
    			for(int z=1;z<=n;z++){
    				if(k[z][j]){
    					swap(k[tmp++][j],k[z][j]);
    				}
    			}
    		}
    	}
    	if(c=='D'){
    		for(int j=1;j<=m;j++){
    			int tmp=n;
    			for(int z=n;z>=1;z--){
    				if(k[z][j]){
    					swap(k[tmp--][j],k[z][j]);
    				}
    			}
    		}
    	}
    	}
	    int tmp=1;
	    for(int i=0;i<n;i++){
	    	for(int j=0;j<m;j++){
	    		if(k[i][j]){
	    			perm[tmp++]=k[i][j];
	    		}
	    	}
	    }
    	int iter=(s.size()/4)-1;
    	for(int i=1;i<tmp;i++){
    		if(!vis[i]){
    			vector<int>q;
    			q.pb(i);
    			while(perm[q.back()]!=i){
    				q.pb(perm[q.back()]);
    			}
    			for(int j=0;j<q.size();j++){
    				vis[q[j]]=1;
    				perm[q[j]]=q[(j+iter)%q.size()];
    			}
    		}
    	}
    	tmp=1;
    	for(int i=1;i<=n;i++){
    		for(int j=1;j<=m;j++){
    			if(k[i][j]){
    				k[i][j]=id[perm[tmp++]];
    			}
    		}
    	}
    }
    for(int i=1;i<=n;i++){
   		for(int j=1;j<=m;j++){
   			if(k[i][j]==1)cout<<"B";
   			else if(k[i][j]==2)cout<<"C";
   			else cout<<".";
   		}
   		cout<<"\n";
    }
    return 0;
}


詳細信息

Subtask #1:

score: 0
Memory Limit Exceeded

Test #1:

score: 1
Accepted
time: 0ms
memory: 5532kb

input:

20 20
.BC.BC.....B.B......
.CC.....BBBC.C....C.
.....BB..B.BBC...CB.
.B.........C.BC..C..
.C.CB.B....B.C...CB.
C..C.BBB...CB.B..CC.
.B.CBCB...CC.B....C.
......B....B.C.B.CC.
C.B..CC......C....B.
.....BC......BC..CC.
.BC..CC....B.....C..
.....C.....BBBC...C.
.C.........BBBB..BCC
...CBBB....B.B....B.
...

output:

CCCBBCBCCBCCBBBCCBB.
CCBCCBCBBCBBCCC.....
BBCBCBBCBBBB........
CCCBBCCBBCCC........
CCBBCBBCBBBC........
BBCBCCBBBCBC........
BBBCBBB.............
CCCBCCC.............
BBCBBBC.............
BBCCBCC.............
CBBBBB..............
BCCCB...............
BCCCB...............
CCCB................
BBC......

result:

ok 20 lines

Test #2:

score: -1
Memory Limit Exceeded

input:

5 13
.CCBCB...BC.C
CBBCCC.C.BBBC
BCCBBB.C.CCB.
CB.C.C...CBC.
B.BCCC.C.B.BB
35
GGGPLDPGPLDLPPPDPGLDLPGLDDPDDPGLDPP

output:


result:


Subtask #2:

score: 0
Memory Limit Exceeded

Test #10:

score: 0
Memory Limit Exceeded

input:

100 100
.C..BB.....BBB.B.C.BC.B..CCC.CB.B.B..C..C.BC...CBBC.B..BC.C.C...BCC.BCCB..CB.CCBC......C.CB.....CCCB
.B.B.C.CC.B...C....CCCC.C.BCCCB..BB.B...C.B...B.C..C....C.CBB.......C.C...B..BBB..C.B.CC....B...BCCB
CB.BCCBB...CC....B.BCB....B.C....BC....BB.BC..C.BBBB....C..CCCC...C.BBCC..BB.C..C.CBCBB..B...

output:


result:


Subtask #3:

score: 0
Memory Limit Exceeded

Test #19:

score: 1
Accepted
time: 21ms
memory: 7576kb

input:

500 500
BCCC..CBBBC.CC.CC..B.C.C..B...CCCC...C...CCBBC.C..BBB.B...BCCBBB..B.CBC.BCB..BB..B.CC...BC.B..BB.C.BBBCB.B..CCCBC.C.BBB..BC.CCBC.B.BC.BBB..CB..C.CC.BCC.......C..C...CCBB...B.C.C.B.C..C...CCC..CB.BBCCC...CCBB...C....CC..B.CB......C.B.......C..BB.....C.BBB....B........C.....B...CCB.C.B..CCCBCC...

output:

BBCBCCCBBCCBBBCBBBBCCCCCBCBBBBCCCBBBBBCBBBBCCCCBBCBBBCBCBBCCBBCCBBCBCBBBCBBBBCCCCBCBBCBCBBBBBCCBCBCBCBBCBCCCBCCBBBCBCCCBBCCCCCCBCBCBBBBCBBBCBCCCCCCBCCBCCCCBCCBCBBBCBBBBCBBBBBBCCCBCCBCBBCBBCCCBBBBCCBCBBCBCCBCCCCCBCBBCBCCCCCBCCBCCCBCCCCCBCCBCBCBBBBCCBBBBCBCCCCCCBCBBCCBBCBCBBCCCBBBBBBBCCCCCCCBBBCBBBCBC...

result:

ok 500 lines

Test #20:

score: -1
Memory Limit Exceeded

input:

394 74
C.C.B.B....C...B..C..B.CCC...B..BB..BB.BB.C.BC..B..BBB......CB.CB..BBC.B.C
C.B..BB..CC....BC........C....B.CB.....B..C.C.B.BBB..B.....BBB.B...BBC...B
...CC.C....CB..B...BCB..BC..BB...C......C.B.....B.B.BBC...BC.B.BB....B.B.C
..CCB.B....B.C.B.CC.C...C...BCB..B....CCC.C.CC..C...CBBB...B.BC.C..B...

output:


result:


Subtask #4:

score: 0
Wrong Answer

Test #28:

score: 1
Accepted
time: 3ms
memory: 7552kb

input:

10 20
........BC.....B....
....C.C..........B.C
.C..C...B..B.....CB.
.C..B.C.BC.C..B.B..B
....C..........BC..B
.C..B...BB....C.C.CB
.B..B.C........B....
.B..B.........BC...B
.B..B...C..B........
....B...B..C..C..B..
10000
DPLGPDLGPDLGPPPDDLGPDLGPDLGPDLGPPDLGGPDLGPDLGPDLGPPPDLGPDLGPDLGPDLGPGDLDGPDLGP...

output:

BBBCBCBBCCCC........
BBCCCBBBBBBC........
BCBBCCCBBBB.........
CCCCBBB.............
CCBC................
BCB.................
B...................
B...................
B...................
....................

result:

ok 10 lines

Test #29:

score: -1
Wrong Answer
time: 2ms
memory: 5584kb

input:

2 16
....BCB.........
B...........C...
5383
GGGDGDDGDGDDDGDGGGDDGDDDDGGDGGDDDDGDDGGDGDGGDDGDGGDDDGGGDDDDGGGDGGDGGGDGGGGDGGGDGDGDDDGDDGGDDDDGDDGGDGDDGGDDDGDDDGDGDDDDDDDGDDGDDDGDGGDGDGGGDDDGGGGGDGDDGGDGGDDGGGGDGGGGGGGGGGDGGGDDGGDGDDDDGDGDGGDDDGGGGGGGDDDDGGDDDGGDGGGGGDGGDGDGGGDDGGGGDGDDDDGDDDDDGGGDGGDG...

output:

................
................

result:

wrong answer 2nd lines differ - expected: '...........BBCBC', found: '................'

Subtask #5:

score: 0
Memory Limit Exceeded

Test #37:

score: 0
Memory Limit Exceeded

input:

200 200
...C.C.B....CC......CB....C.......B.......BB..B..B.....B..BB..B..C.B.BC..CB............CC....C.C.C..CCCBC..B...B.C...........C..B...B..C..B...........B.B.......CB..B..C.BC..B.C.CB.C..BB..CB.C...C.....
..CC.BBBB....B....BB.C....BBC...BCC....B.....BC....C.B......B.........C.......CC..CCBCB.......

output:


result:


Subtask #6:

score: 0
Memory Limit Exceeded

Test #46:

score: 0
Memory Limit Exceeded

input:

300 300
BC.CCB.C..C......BC.....BCB..C.BB...CBBCC...BC.BB...B..CBBBB...C.BC....CC.BCCB.CC.B..B.C..BC.....CC.C.B.BCCB.BC..B.B.CB.B.CBB..B....B....BC..BB.B...C.CCB..CBCCB.CC...B.BB.B..B..CC.CCBBC.C.C.B...B.BB.....CCB.CC..BBBCB..CC..CCB.CCB....BC...BCBBCCBCCCBC.BB.....C...CCCB..CB.CBBC.CB..C.C.C.B..C.....

output:


result:


Subtask #7:

score: 0
Memory Limit Exceeded

Test #54:

score: 0
Memory Limit Exceeded

input:

500 500
...C..CBBCB....CBBBC....CB.C....BB.CCB.BBB...B.CC.B..CBBC.BCBCC....CBB.C.BCCB.C.C.CB.C.B.BC..B..BCCCB...B.B.B.CCBB.CB....BBCC.CCCC.C...CBB...BB...BBC.C..CBCBCCC.CB..C.CC.CBC.B.C..B....C.CBB......C.BC.BB.C.C..CB..B.C..CB......CCBC...BBB.BB..CC...C....C.B...B.BB.B..CC.B.C.BCBB.B.CC.BCBB.B...BB...

output:


result:


Subtask #8:

score: 0
Memory Limit Exceeded

Test #63:

score: 0
Memory Limit Exceeded

input:

500 500
CC.CC...B..BCCB..C..C..CBBB..C..C..CCB.BC.CB.CCCCC..C......BC....BB.B.BB.....C...B..BBC...C....C.BB...BCBB.BCB.CC...B.CC....B.CC.B..BC.CB...C...BC.BBB...B.B.B..B.CB.CBBC..B.....CB.CB..BB.B.CCB.B.B..CC.B..CC.C.BB.BC..B.CBC.BB.....C......B.......C..C..BCB.BB.C.B....B..CB...B.CB...B.BCC.B.BB......

output:


result:


Subtask #9:

score: 0
Memory Limit Exceeded

Test #71:

score: 0
Memory Limit Exceeded

input:

500 500
...................................C................C........C......B........C...........B..BC..................................................................C.....C.............C..............................................B...........B.........B.........B...B..C............B...............

output:


result:


Subtask #10:

score: 0
Memory Limit Exceeded

Test #80:

score: 0
Memory Limit Exceeded

input:

500 500
.BBB.BCB.CCCBCBCCB.CB.CBBBCCCCBBBCBBCBCC.B.BCBCBBB.BBBBCCBBB.BBBBCCC.CCBBBCBCCCBBBCBCBBBCBBC.C.CBBBBBBC.BCCBBBBCBBCB.BCBB.CC.BCBB.CBB.BBBCCBCBCCBBC.CCCCBB.BBCBBBCBBBBCBBCBC.BBBBCBBBCCCC.CBBCCCB.C.C.CBBC.CCBBCCCCCCBC.BCCCBCCBCB.BBCBCCB.BCCBBC.BB.BCCCCCCCCCCCBBCC.C.CCCCBBBCCCB.BBBCBB..B.B.CBB....

output:


result: