Submission #969348

#TimeUsernameProblemLanguageResultExecution timeMemory
969348steveonalexLand of the Rainbow Gold (APIO17_rainbow)C++17
35 / 100
3056 ms14888 KiB
#include <bits/stdc++.h> #include "rainbow.h" using namespace std; typedef long long ll; typedef unsigned long long ull; #define ALL(v) (v).begin(), (v).end() #define MASK(i) (1LL << (i)) #define GETBIT(mask, i) (((mask) >> (i)) & 1) // mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); mt19937_64 rng(1); ll rngesus(ll l, ll r){return ((ull) rng()) % (r - l + 1) + l;} ll max(ll a, ll b){return (a > b) ? a : b;} ll min(ll a, ll b){return (a < b) ? a : b;} ll LASTBIT(ll mask){return mask & (-mask);} ll pop_cnt(ll mask){return __builtin_popcountll(mask);} ll ctz(ll mask){return __builtin_ctzll(mask);} ll clz(ll mask){return __builtin_clzll(mask);} ll logOf(ll mask){return 63 - clz(mask);} template <class T1, class T2> bool minimize(T1 &a, T2 b){ if (a > b){a = b; return true;} return false; } template <class T1, class T2> bool maximize(T1 &a, T2 b){ if (a < b){a = b; return true;} return false; } template <class T> void printArr(T& a, string separator = " ", string finish = "\n", ostream& out = cout){ for(auto i: a) out << i << separator; out << finish; } template <class T> void remove_dup(vector<T> &a){ sort(ALL(a)); a.resize(unique(ALL(a)) - a.begin()); } const int INF = 1e9 + 69; int dx[] = {-1, 1, 0, 0}; int dy[] = {0, 0, -1, 1}; #define Point pair<int, int> vector<Point> dragon, verti_edge, hori_edge, vertices; int xL, xR, yL, yR; int cur_face; void init(int n, int m, int sr, int sc, int k, char *S) { Point coord = {sr, sc}; dragon.push_back(coord); for(int i = 0; i<k; ++i){ if (S[i] == 'N') coord.first--; else if (S[i] == 'S') coord.first++; else if (S[i] == 'W') coord.second--; else coord.second++; dragon.push_back(coord); } remove_dup(dragon); for(pair<int, int> i: dragon){ for(int d = 0; d < 4; ++d){ if (d <= 1) hori_edge.push_back({i.first - (d == 0), i.second}); else verti_edge.push_back({i.first, i.second - (d == 2)}); } } remove_dup(hori_edge); remove_dup(verti_edge); for(pair<int, int> i: hori_edge) { vertices.push_back({i.first, i.second-1}); vertices.push_back({i.first, i.second}); } for(pair<int, int> i: verti_edge){ vertices.push_back({i.first-1, i.second}); vertices.push_back({i.first, i.second}); } remove_dup(vertices); // cout << "Dragon: \n"; // for(pair<int, int> i: dragon) cout << i.first << " " << i.second << "\n"; // cout << "Horizontal Edge: \n"; // for(pair<int, int> i: hori_edge) cout << i.first << " " << i.second << "\n"; // cout << "Vertical Edge: \n"; // for(pair<int, int> i: verti_edge) cout << i.first << " " << i.second << "\n"; // cout << "Vertices: \n"; // for(pair<int, int> i: vertices) cout << i.first << " " << i.second << "\n"; cur_face = 2 + hori_edge.size() + verti_edge.size() - vertices.size() - dragon.size(); xL = yL = INF; xR = yR = 0; for(pair<int, int> i: dragon){ maximize(xR, i.first); maximize(yR, i.second); minimize(xL, i.first); minimize(yL, i.second); } } int colour(int ar, int ac, int br, int bc) { if (ar < xL && ac < yL && br > xR && bc > yR) return cur_face; int cnt = 0; int v_cnt = ((br - ar) + (bc - ac)) * 2, e_cnt = v_cnt; int block_cnt = 0; for(pair<int, int> i: dragon){ if (ar <= i.first && i.first <= br && ac <= i.second && i.second <= bc) block_cnt++; } for(pair<int, int> i: vertices){ if (ar <= i.first && i.first < br && ac <= i.second && i.second < bc) v_cnt++; } for(pair<int, int> i: hori_edge){ if (ac <= i.second && i.second <= bc && ar <= i.first && i.first < br) e_cnt++; } for(pair<int, int> i: verti_edge){ if (ar <= i.first && i.first <= br && ac <= i.second && i.second < bc) e_cnt++; } return 1 + e_cnt - v_cnt - block_cnt; } // int main(void){ // ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); // freopen("input.inp", "r", stdin); // int n, m, k; cin >> n >> m; // int sr, sc; cin >> sr >> sc; // cin >> k; // string s; cin >> s; // init(n, m, sr, sc, k, (char*) s.c_str()); // int q; cin >> q; // while(q--) { // int a, b, c, d; cin >> a >> b >> c >> d; // cout << colour(a, b, c, d) << "\n"; // } // return 0; // }

Compilation message (stderr)

rainbow.cpp: In function 'int colour(int, int, int, int)':
rainbow.cpp:112:9: warning: unused variable 'cnt' [-Wunused-variable]
  112 |     int cnt = 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...