Submission #887739

#TimeUsernameProblemLanguageResultExecution timeMemory
887739hamidh100Land of the Rainbow Gold (APIO17_rainbow)C++17
12 / 100
44 ms8528 KiB
#include "rainbow.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<int, int> PII; typedef pair<ll, ll> PLL; typedef vector<int> VI; typedef vector<ll> VL; #define PB push_back #define MP make_pair #define all(a) (a).begin(), (a).end() #define endl '\n' #define dbg(x) cerr << '[' << #x << ": " << x << "]\n" #define dbg2(x, y) cerr << '[' << #x << ": " << x << ", " << #y << ": " << y << "]\n" #define YES cout << "YES\n" #define NO cout << "NO\n" const ll INF = (ll)2e18 + 1386; const ld EPS = 0.000000000000001; const int MOD = 1e9 + 7; inline int _add(int a, int b){ int res = a + b; return (res >= MOD ? res - MOD : res); } inline int _neg(int a, int b){ int res = (abs(a - b) < MOD ? a - b : (a - b) % MOD); return (res < 0 ? res + MOD : res); } inline int _mlt(ll a, ll b){ return (a * b % MOD); } inline void fileIO(string i, string o){ freopen(i.c_str(), "r", stdin); freopen(o.c_str(), "w", stdout); } const int MAXN = 2e5 + 5; int n, m; int a[MAXN][3]; inline int c(int x, int y){ return (x - 1) * m + y; } int ps[MAXN][3]; void init(int R, int C, int sr, int sc, int M, char *S) { n = R, m = C; a[sc][sr] = 1; for (int i = 0; i < M; i++){ char ch = S[i]; if (ch == 'N') a[sc][--sr] = 1; else if (ch == 'S') a[sc][++sr] = 1; else if (ch == 'E') a[++sc][sr] = 1; else a[--sc][sr] = 1; } for (int i = 1; i <= m; i++){ ps[i][1] = ps[i - 1][1] + (a[i - 1][1] == 1 && a[i][1] == 0); ps[i][2] = ps[i - 1][2] + (a[i - 1][2] == 1 && a[i][2] == 0); ps[i][0] = ps[i - 1][0] + ((a[i - 1][1] == 1 && a[i][1] == 0 && !(a[i][2] == 0 && a[i - 1][2] == 0)) || (a[i - 1][2] == 1 && a[i][2] == 0 && !(a[i][1] == 0 && a[i - 1][1] == 0))); } } int dx[] = {0, 0, +1, -1}; int dy[] = {+1, -1, 0, 0}; int colour(int ar, int ac, int br, int bc) { if (ar == br){ return ps[bc][ar] - ps[ac - 1][ar] + (a[ac][ar] == 0 && a[ac - 1][ar] == 0); } return ps[bc][0] - ps[ac - 1][0] + ((a[ac - 1][1] == 0 && a[ac][1] == 0) || (a[ac - 1][2] == 0 && a[ac][2] == 0)); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...