Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- using pii=pair<char,pair<int,int>>;
- int n,m,score;
- char ar[10][10];
- int dx[]={1,-1,0,0};
- int dy[]={0,0,1,-1};
- void print_block(void){
- for(int i=1;i<=n;i++){
- for(int j=1;j<=m;j++){
- printf("%c ",ar[i][j]);
- }
- printf("\n");
- }
- }
- bool position(int i,int j){
- if(i<1||i>n||j<1||j>m) return false;
- return true;
- }
- bool move_block(){
- queue <pii> q;
- for(int i=1;i<=n;i++){
- for(int j=1;j<=m;j++){
- if(65<=ar[i][j] and ar[i][j]<=90){
- q.push({ ar[i][j] , {i,j} });
- }
- }
- }
- bool move_or_not=false;
- while(q.size()>0){
- int ui,uj;
- char a;
- a=q.front().first;
- ui=q.front().second.first;
- uj=q.front().second.second;
- q.pop();
- ar[ui][uj]=a;
- if( (position(ui+1,uj) or ui+1==n) and ar[ui+1][uj]=='-'){
- move_or_not=true;
- ar[ui][uj]='-';
- q.push({a,{ui+1,uj}});
- }
- }
- if(move_or_not)
- return true;
- else
- return false;
- }
- bool check_delete(int ui,int uj){
- bool rt=false;
- for(int d=0;d<4;d++){
- int vi,vj;
- vi=dx[d]+ui;
- vj=dy[d]+uj;
- if(position(vi,vj) && ar[vi][vj]==ar[ui][uj] )
- rt=true;
- }
- if(rt)
- return true;
- else
- return false;
- }
- bool delete_block(){
- queue <pii> q;
- for(int i=1;i<=n;i++){
- for(int j=1;j<=m;j++){
- if( (65<=ar[i][j] and ar[i][j]<=90) and check_delete(i,j) ){
- q.push({ar[i][j],{i,j} });
- }
- }
- }
- bool can_delete=false;
- while(q.size()>0){
- int ui,uj;
- char a;
- a=q.front().first;
- uj=q.front().second.second;
- ui=q.front().second.first;
- q.pop();
- if(ar[ui][uj]!=a)
- continue;
- can_delete=true;
- ar[ui][uj]='-';
- score+=5;
- for(int d=0;d<4;d++){
- int vi,vj;
- vi=ui+dx[d];
- vj=uj+dy[d];
- if(position(vi,vj) and ar[vi][vj]==a){
- q.push({a,{vi,vj}});
- }
- }
- }
- if(can_delete)
- return true;
- else
- return false;
- }
- int main(){
- scanf("%d%d",&n,&m);
- for(int i=1;i<=n;i++){
- for(int j=1;j<=m;j++){
- scanf(" %c",&ar[i][j]);
- }
- }
- int t;
- scanf("%d",&t);
- while(t--){
- int ui,uj,drt;
- char opr;
- scanf("%d%d",&ui,&uj);
- ui++;
- uj++;
- scanf(" %c",&opr);
- if(opr=='L') drt=-1;
- else drt=1;
- if(!position(ui,uj+drt) || ar[ui][uj+drt]!='-' || !(65<=ar[ui][uj] and ar[ui][uj]<=90)) {
- score-=5;
- continue;
- }
- bool stop=false;
- int c=1;
- while(!stop){
- if(c==1){
- ar[ui][uj+drt]=ar[ui][uj];
- ar[ui][uj]='-';
- uj=uj+drt;
- move_block();
- delete_block();
- }
- if(!move_block()) break;
- if(!delete_block()) break;
- c++;
- }
- }
- printf("%d\n",score);
- print_block();
- return 0;
- }
- /*
- 4 4
- #B-B
- BA-#
- AB-#
- #A-B
- 5
- 0 1 R
- 4 4
- #B-B
- BA-B
- AB-#
- #A-B
- 3
- 0 1 R
- 0 3 L
- 1 3 L
- */
Add Comment
Please, Sign In to add comment