Submission #409184

#TimeUsernameProblemLanguageResultExecution timeMemory
409184cheissmartLand of the Rainbow Gold (APIO17_rainbow)C++14
0 / 100
7 ms3464 KiB
#ifndef CHEISSMART #include "rainbow.h" #endif #include <bits/stdc++.h> #define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0); #define F first #define S second #define V vector #define PB push_back #define MP make_pair #define EB emplace_back #define ALL(v) (v).begin(), (v).end() using namespace std; typedef long long ll; typedef pair<int, int> pi; typedef V<int> vi; string _reset = "\u001b[0m", _yellow = "\u001b[33m", _bold = "\u001b[1m"; void DBG() { cerr << "]" << _reset << endl; } template<class H, class...T> void DBG(H h, T ...t) { cerr << to_string(h); if(sizeof ...(t)) cerr << ", "; DBG(t...); } #ifdef CHEISSMART #define debug(...) cerr << _yellow << _bold << "Line(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__) #else #define debug(...) #endif const int INF = 1e9 + 7, N = 2e5 + 7; int di[] = {1, -1, 0, 0}, dj[] = {0, 0, 1, -1}; V<pi> bad; int R, C; int a[2][N], nw[3][N], nwp[3][N]; void init(int R, int C, int sr, int sc, int M, char *S) { ::R = R, ::C = C; bad.EB(sr - 1, 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++; bad.EB(sr - 1, sc - 1); } sort(ALL(bad)); bad.resize(unique(ALL(bad)) - bad.begin()); for(pi p:bad) a[p.F][p.S] = 1; for(int i = 0; i < 2; i++) { for(int j = 0; j < N; j++) { if(a[i][j] == 0 && (j == 0 || a[i][j - 1] == 1)) nw[i][j] = 1; nwp[i][j] = nw[i][j] + (j ? nwp[i][j - 1] : 0); } } for(int j = 0; j < N; j++) { if(a[0][j] == 0 || a[1][j] == 0) { nw[2][j] = 1; if(j && a[0][j] ==0 && a[0][j - 1] == 0) nw[2][j] = 0; if(j && a[1][j] ==0 && a[1][j - 1] == 0) nw[2][j] = 0; } nwp[2][j] = nwp[2][j] + (j ? nwp[2][j - 1] : 0); } } int colour(int ar, int ac, int br, int bc) { ar--, ac--, br--, bc--; if(bc == ac) { return a[ar][ac] == 0 || a[br][ac] == 0; } int res = 0; if(ac == bc) { res += nwp[ac][br] - nwp[ac][ar]; if(a[ac][ar] == 0 && nw[ac][ar + 1] == 0) res++; } else { res += nwp[2][br] - nwp[2][ar]; if(a[ac][ar] == 0 || a[bc][ar] == 0) if(nw[2][ar + 1] == 0) res++; } return res; }
#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...