Submission #1353386

#TimeUsernameProblemLanguageResultExecution timeMemory
1353386ramzialoulouLand of the Rainbow Gold (APIO17_rainbow)C++20
12 / 100
28 ms4204 KiB
#include <bits/stdc++.h>
#include "rainbow.h"

using namespace std;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, 1, -1};
const int N = int(2e5) + 9;
int a[3][N];
int pre[4][N];
int n, m;

void init(int R, int C, int sr, int sc, int M, char *S) {
  n = R, m = C;
  a[sr][sc] = 1;
  for (int i = 0; i < M; i++) {
    if (S[i] == 'N') {
      sr--;
    } else if (S[i] == 'S') {
      sr++;
    } else if (S[i] == 'W') {
      sc--;
    } else {
      sc++;
    }
    a[sr][sc] = 1;
  }
  a[1][0] = a[2][0] = 1;
  for (int j = 1; j <= m; j++) {
    pre[1][j] = pre[1][j - 1] + (a[1][j - 1] && !a[1][j]);
    pre[2][j] = pre[2][j - 1] + (a[2][j - 1] && !a[2][j]);
    pre[3][j] = pre[3][j - 1] + (a[1][j - 1] && a[2][j - 1] && (!a[1][j] || !a[2][j]));
  }
}

int colour(int ar, int ac, int br, int bc) {
  if (ar == br) {
    return pre[ar][bc] - pre[ar][ac - 1] + (!a[ar][ac - 1] && !a[ar][ac]);
  } else {
    return pre[3][bc] - pre[3][ac - 1] + (a[1][ac - 1] + a[2][ac - 1] != 2 && a[1][ac] + a[2][ac] != 2);
  }
}
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...