This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "rainbow.h"
#include<bits/stdc++.h>
using namespace std;
vector<vector<int>> grid;
void init(int R, int C, int sr, int sc, int M, char *S) {
vector<int> auxi(C,0);
for(int i=0;i<R;i++){
grid.push_back(auxi);
}
sr--;
sc--;
grid[sr][sc]=-1;
for(int i=0;i<M;i++){
switch(S[i]){
case 'N':
sr--;
break;
case 'S':
sr++;
break;
case 'W':
sc--;
break;
case 'E':
sc++;
break;
}
grid[sr][sc]=-1;
}
for(int i=0;i<R;i++){
bool xd=true;
int ante=0;
for(int j=0;j<C;j++){
if(xd && grid[i][j]==0){
ante++;
grid[i][j]=ante;
xd=false;
}else{
xd=true;
}
}
}
}
int colour(int ar, int ac, int br, int bc) {
int canti=0;
ar--;
ac--;
br--;
bc--;
//vector<vector<char>> clon(grid.begin(),grid.end());
if(ar==br){
if(grid[ar][ac]!=-1 && grid[ar][bc]!=-1){
canti=grid[ar][bc]-grid[ar][ac]+1;
}else if(grid[ar][ac]==-1 && grid[ar][bc]!=-1){
for(int i=ac;i<=bc;i++){
if(grid[ar][i]!=-1){
canti=grid[ar][bc]-grid[ar][i]+1;
break;
}
}
}else if(grid[ar][ac]!=-1 && grid[ar][bc]==-1){
for(int i=bc;i>=ac;i--){
if(grid[ar][i]!=-1){
canti=grid[ar][i]-grid[ar][ac]+1;
break;
}
}
}else{
for(int i=bc;i>=ac;i--){
if(grid[ar][i]!=-1){
canti=grid[ar][i];
break;
}
}
for(int i=ac;i<=bc;i++){
if(grid[ar][i]!=-1){
canti=canti-grid[ar][i]+1;
break;
}
}
}
}else{
for(int k=ar;k<=br;k++){
if(grid[k][ac]!=-1 && grid[k][bc]!=-1){
canti+=grid[k][bc]-grid[k][ac]+1;
}else if(grid[k][ac]==-1 && grid[k][bc]!=-1){
for(int i=ac;i<=bc;i++){
if(grid[k][i]!=-1){
canti+=grid[k][bc]-grid[k][i]+1;
break;
}
}
}else if(grid[k][ac]!=-1 && grid[k][bc]==-1){
for(int i=bc;i>=ac;i--){
if(grid[k][i]!=-1){
canti+=grid[k][i]-grid[k][ac]+1;
break;
}
}
}else{
for(int i=bc;i>=ac;i--){
if(grid[k][i]!=-1){
canti+=grid[k][i];
break;
}
}
for(int i=ac;i<=bc;i++){
if(grid[k][i]!=-1){
canti-=grid[k][i];
canti++;
break;
}
}
}
}
if(canti==2){
if((grid[ar][ac]!=-1 && grid[br][ac]!=-1) || (grid[ar][bc]!=-1 && grid[br][bc]!=-1)){
canti=1;
}
}
if(grid[br][ac]!=-1 && grid[ar][ac]!=-1){
canti--;
}
if(grid[br][bc]!=-1 && grid[ar][bc]!=-1){
canti--;
}
}
return canti;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |