#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
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: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)
| ^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
837 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
816 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
12740 KB |
Output is correct |
2 |
Correct |
11 ms |
10956 KB |
Output is correct |
3 |
Correct |
12 ms |
12096 KB |
Output is correct |
4 |
Correct |
10 ms |
10564 KB |
Output is correct |
5 |
Correct |
14 ms |
12720 KB |
Output is correct |
6 |
Correct |
18 ms |
13936 KB |
Output is correct |
7 |
Correct |
11 ms |
7320 KB |
Output is correct |
8 |
Correct |
18 ms |
19916 KB |
Output is correct |
9 |
Correct |
18 ms |
19984 KB |
Output is correct |
10 |
Correct |
17 ms |
19880 KB |
Output is correct |
11 |
Correct |
19 ms |
13500 KB |
Output is correct |
12 |
Correct |
19 ms |
13628 KB |
Output is correct |
13 |
Correct |
18 ms |
13620 KB |
Output is correct |
14 |
Correct |
26 ms |
23096 KB |
Output is correct |
15 |
Correct |
13 ms |
12752 KB |
Output is correct |
16 |
Correct |
13 ms |
12740 KB |
Output is correct |
17 |
Correct |
18 ms |
19904 KB |
Output is correct |
18 |
Correct |
18 ms |
19848 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
823 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
815 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |