Submission #209971

#TimeUsernameProblemLanguageResultExecution timeMemory
209971kshitij_sodaniDango Maker (JOI18_dango_maker)C++17
0 / 100
5 ms376 KiB
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
typedef int64_t llo;
#define a first
#define  b second
#define endl "\n"
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n,m;
	cin>>n>>m;
	int it[n][m];
	char s;
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			cin>>s;
			if(s=='R'){
				it[i][j]=0;
			}
			else if(s=='G'){
				it[i][j]=1;
			}
			else{
				it[i][j]=2;
			}
		}
	}
	int tot=0;
	for(int ii=0;ii<n+m-1;ii++){
		int co=0;
		int co2=0;
		for(int jj=0;jj<ii+1;jj++){
			int i,j;
			j=jj;
			i=ii-j;
			if(i>=n or j>=m){
				continue;
			}

			/*if(ii<=min(n,m)-1){
				j=jj;
				i=ii-j;
			}
			else{
				j=ii-(min(n,m)-1);
				i=ii-j;
			}*/
			int st=1;
			int stt=1;
			if(j>0  and it[i][j-1]==0 and j+1<m and it[i][j+1]==2 and it[i][j]==1){
				if(j%2==0){
					co+=1;
					st=0;
				}
				else{
					co2+=1;
					stt=0;
				}
			}
			else{
				if(j%2==0){
					tot+=(co+1)/2;
					co=0;
				}
				else{
					tot+=(co2+1)/2;
					co2=0;
				}
			}
			if(i>0 and i+1<n and it[i-1][j]==0 and it[i+1][j]==2 and it[i][j]==1){
				if(j%2==1){
					if(stt==0){
						if(co%2==1){
							tot+=(co+1)/2;
							co=0;
						}
						else{
							tot+=(co2+1)/2;
							co2=0;
							co+=1;
						}
					}
					else{
						co+=1;
					}
				}
				else{
					if(st==0){
						if(co%2==1){
							tot+=(co+1)/2;
							co=0;
							co2+=1;
						}
						else{
							tot+=(co2+1)/2;
							co2=0;
						}
					}
					else{
						co2+=1;
					}
				}
			}
			else{
				if(j%2==1){

					tot+=(co+1)/2;
					co=0;
				}
				else{
					tot+=(co2+1)/2;
					co2=0;
				}
			}
	//		cout<<co<<" "<<co2<<endl;
		}
		tot+=(co+1)/2;
		tot+=(co2+1)/2;
	//	cout<<tot<<endl;

	}

	cout<<tot<<endl;






	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...