Submission #948315

#TimeUsernameProblemLanguageResultExecution timeMemory
948315vjudge1Land of the Rainbow Gold (APIO17_rainbow)C++17
0 / 100
11 ms21084 KiB
#include "rainbow.h" #include <bits/stdc++.h> #define ll int #define str string #define ins insert #define ld long double #define pb push_back #define pf push_front #define pof pop_front() #define pob pop_back() #define lb lower_bound #define ub upper_bound #define endl "\n" #define fr first #define sc second #define all(x) x.begin(),x.end() #define rall(x) x.rbegin(),x.rend() #define sz size() #define vll vector<ll> #define arr array #define pll vector<pair<ll,ll>> using namespace std; template<class S,class T> bool chmin(S &a,const T &b) { return a>b?(a=b)==b:false; } template<class S,class T> bool chmax(S &a,const T &b) { return a<b?(a=b)==b:false; } const ll inf=1e18; const ll mod=1e9+7; const ll N=2e5+5; const ld eps=1e-9; bool vis[55][N]; bool f[55][N]; ll l=inf,r,u=inf,d; ll xd[4]={-1,1,0,0},yd[4]={0,0,-1,1}; bool ok(ll x,ll y){ return !vis[x][y] && !f[x][y] && x>=u && x<=d && y>=l && y<=r; } void bfs(ll x,ll y){ ll i; vis[x][y]=1; for(i=0;i<4;i++){ ll nx=x+xd[i],ny=y+yd[i]; if(ok(nx,ny))bfs(nx,ny); } } ll pref[4][N]; bool row; void init(int r, int c, int sr, int sc, int m, char *s) { ll i,j; ll x=sr,y=sc; f[x][y]=1; for(i=0;i<m;i++){ if(s[i]=='N')x--; if(s[i]=='S')x++; if(s[i]=='W')y--; if(s[i]=='E')y++; f[x][y]=1; chmin(u,x); chmax(d,x); chmin(l,y); chmax(r,y); } if(r==2) { row=1; for(i=1;i<3;i++){ for(j=1;j<=r;j++){ pref[i][j]=pref[i][j-1]; if(f[i][j+1] && !f[i][j])pref[i][j]++; } } } } int colour(int ar, int ac, int br, int bc) { if(row){ if(u==d){ if(ac>=l && bc<=r && ar>=u && br<=d)return 0; if(ac<=l && bc>=r && ar>=u && br<=d)return 2; return 1; } ll c=0; if(ar==br){ if(f[ar][bc+1] && !f[ar][bc])c=1; return pref[ar][bc]-pref[ar][ac-1]+c; } if(f[ar][bc+1] && !f[ar][bc])c++; if(f[br][bc+1] && !f[br][bc])c++; if(ac<l)c--; if(bc>r)c--; return pref[0][bc]-pref[0][ac-1]+pref[1][bc]-pref[1][ac-1]+c; } u=ar,l=ac,d=br,r=bc; ll c=0,i,j; for(i=u;i<=d;i++){ for(j=l;j<=r;j++){ vis[i][j]=0; } } for(i=u;i<=d;i++){ for(j=l;j<=r;j++){ if(vis[i][j] || f[i][j]) continue; bfs(i,j); c++; } } return c; }

Compilation message (stderr)

rainbow.cpp:31:14: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+18' to '2147483647' [-Woverflow]
   31 | const ll inf=1e18;
      |              ^~~~
#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...