Submission #566975

#TimeUsernameProblemLanguageResultExecution timeMemory
566975MazaalaiHexagonal Territory (APIO21_hexagon)C++17
3 / 100
1 ms212 KiB
#include "hexagon.h" #include <bits/stdc++.h> using ll = long long; using namespace std; int dx[] = {-1, 0, 1, 1, 0, -1}; int dy[] = {0, 1, 1, 0, -1, -1}; ll n, A, B; const int MOD = 1e9 + 7; ll power(ll a, ll b, ll p) { ll res = 1; while(b > 0) { if (b & 1) res = res * a % p; a = a * a % p; b /= 2; } return res; } ll inv(ll a, ll p) { return power(a, p-2, p); } int draw_territory(int _n, int _A, int _B, std::vector<int> d, std::vector<int> l) { n = _n; A = _A; B = _B; if (n == 3) { ll x = l[0]+1; if (l[0] != l[1] || l[1] != l[2]) x = x / (x - x); ll res = ( ( (x+1) * (x) / 2 % MOD * A % MOD) + (B * ( (x * (x+1) / 2) % MOD + x * (x + 1) % MOD * (2*x + 1) % MOD * inv(6, MOD) %MOD ) % MOD ) % MOD )%MOD; return (res % MOD + MOD) % MOD; } return 0; }

Compilation message (stderr)

hexagon.cpp: In function 'int draw_territory(int, int, int, std::vector<int>, std::vector<int>)':
hexagon.cpp:29:49: warning: division by zero [-Wdiv-by-zero]
   29 |         if (l[0] != l[1] || l[1] != l[2]) x = x / (x - x);
      |                                               ~~^~~~~~~~~
#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...