Submission #824863

#TimeUsernameProblemLanguageResultExecution timeMemory
824863HanksburgerHexagonal Territory (APIO21_hexagon)C++17
0 / 100
888 ms1048576 KiB
#include "hexagon.h" #include <bits/stdc++.h> using namespace std; const pair<long long, long long> dir[7]={{0, 0}, {1, 0}, {0, 1}, {-1, 1}, {-1, 0}, {0, -1}, {1, -1}}; const long long mod=1000000007; vector<pair<long long, long long> > coord, tmp, vertices; vector<long long> d, l; int draw_territory(int nn, int aa, int bb, vector<int> dd, vector<int> ll) { long long n=nn, a=aa, b=bb, curX=0, curY=0, mx=-1e9, mn=1e9, corner=0, flip, sz, ind, sum1=0, sum2=0; for (long long i=0; i<n; i++) d.push_back(dd[i]), l.push_back(ll[i]); for (long long i=0; i<n; i++) { for (long long j=0; j<l[i]; j++) { if (mx<curX) { mx=curX; if (d[(i+n-1)%n]==2 || (d[(i+n-1)%n]==1 && (d[i]==2 || d[i]==3)) || (d[(i+n-1)%n]==6 && d[i]==2)) flip=0; else flip=1; } tmp.push_back({curX, curY}); curX+=dir[d[i]].first; curY+=dir[d[i]].second; } } if (flip) reverse(tmp.begin(), tmp.end()); sz=tmp.size(); for (long long i=0; i<sz; i++) { coord.push_back(tmp[i]); if (tmp[(i+1)%sz].first==tmp[i].first-1 && tmp[(i+1)%sz].second==tmp[i].second+1) coord.push_back({tmp[i].first-1, tmp[i].second}); else if (tmp[(i+1)%sz].first==tmp[i].first+1 && tmp[(i+1)%sz].second==tmp[i].second-1) coord.push_back({tmp[i].first+1, tmp[i].second}); } sz=coord.size(); mx=-1e9; for (long long i=0; i<sz; i++) { if (mx<coord[i].first) { mx=coord[i].first; mn=coord[i].second; ind=i; } /*else if (mx==coord[i].first && mn>coord[i].second) { mx=coord[i].first; mn=coord[i].second; ind=i; } */ } for (long long i=ind; i<ind+sz; i++) { if (coord[(i+1)%sz].first==coord[i%sz].first+1) { if (corner==0) corner=2; else if (corner==1) { vertices.push_back({coord[i%sz].first, coord[i%sz].second+1}); vertices.push_back({coord[i%sz].first-1, coord[i%sz].second+1}); vertices.push_back({coord[i%sz].first-1, coord[i%sz].second}); corner=2; } else if (corner==2) vertices.push_back({coord[i%sz].first-1, coord[i%sz].second}); else { vertices.push_back({coord[i%sz].first-1, coord[i%sz].second+1}); vertices.push_back({coord[i%sz].first-1, coord[i%sz].second}); corner=2; } } else if (coord[(i+1)%sz].first==coord[i%sz].first-1) { if (corner==0) { vertices.push_back({coord[i%sz].first, coord[i%sz].second}); vertices.push_back({coord[i%sz].first, coord[i%sz].second+1}); corner=1; } else if (corner==1) vertices.push_back({coord[i%sz].first, coord[i%sz].second+1}); else if (corner==2) { vertices.push_back({coord[i%sz].first-1, coord[i%sz].second}); vertices.push_back({coord[i%sz].first, coord[i%sz].second}); vertices.push_back({coord[i%sz].first, coord[i%sz].second+1}); corner=1; } else corner=1; } else if (coord[(i+1)%sz].second==coord[i%sz].second+1) { if (corner==0) vertices.push_back({coord[i%sz].first, coord[i%sz].second}); else if (corner==1) corner=0; else if (corner==2) { vertices.push_back({coord[i%sz].first-1, coord[i%sz].second}); vertices.push_back({coord[i%sz].first, coord[i%sz].second}); corner=0; } else { vertices.push_back({coord[i%sz].first-1, coord[i%sz].second+1}); vertices.push_back({coord[i%sz].first-1, coord[i%sz].second}); vertices.push_back({coord[i%sz].first, coord[i%sz].second}); corner=0; } } else { if (corner==0) { vertices.push_back({coord[i%sz].first, coord[i%sz].second}); vertices.push_back({coord[i%sz].first, coord[i%sz].second+1}); vertices.push_back({coord[i%sz].first-1, coord[i%sz].second+1}); corner=3; } else if (corner==1) { vertices.push_back({coord[i%sz].first, coord[i%sz].second+1}); vertices.push_back({coord[i%sz].first-1, coord[i%sz].second+1}); corner=3; } else if (corner==2) corner=3; else vertices.push_back({coord[i%sz].first-1, coord[i%sz].second+1}); } } if (corner==1) { vertices.push_back({coord[ind].first, coord[ind].second+1}); corner=3; } if (corner==3) { vertices.push_back({coord[ind].first-1, coord[ind].second+1}); corner=2; } if (corner==2) vertices.push_back({coord[ind].first-1, coord[ind].second}); sz=vertices.size(); for (long long i=0; i<sz; i++) { sum1=vertices[i].first*vertices[(i+1)%sz].second; sum2=vertices[i].second*vertices[(i+1)%sz].first; } return abs(sum1-sum2)%mod*500000004%mod*a%mod; }

Compilation message (stderr)

hexagon.cpp: In function 'int draw_territory(int, int, int, std::vector<int>, std::vector<int>)':
hexagon.cpp:10:27: warning: unused variable 'b' [-Wunused-variable]
   10 |     long long n=nn, a=aa, b=bb, curX=0, curY=0, mx=-1e9, mn=1e9, corner=0, flip, sz, ind, sum1=0, sum2=0;
      |                           ^
hexagon.cpp:10:58: warning: variable 'mn' set but not used [-Wunused-but-set-variable]
   10 |     long long n=nn, a=aa, b=bb, curX=0, curY=0, mx=-1e9, mn=1e9, corner=0, flip, sz, ind, sum1=0, sum2=0;
      |                                                          ^~
hexagon.cpp:143:38: warning: 'ind' may be used uninitialized in this function [-Wmaybe-uninitialized]
  143 |         vertices.push_back({coord[ind].first, coord[ind].second+1});
      |                                      ^
hexagon.cpp:30:5: warning: 'flip' may be used uninitialized in this function [-Wmaybe-uninitialized]
   30 |     if (flip)
      |     ^~
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...