이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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=-1, 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=-1;
for (long long i=0; i<sz; i++)
{
// cout << "coord " << coord[i].first << ' ' << coord[i].second << '\n';
if (mx<coord[i].first)
{
mx=coord[i].first;
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)/2%mod*a%mod;
}
컴파일 시 표준 에러 (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=-1, corner=0, flip, sz, ind, sum1=0, sum2=0;
| ^
hexagon.cpp:137:38: warning: 'ind' may be used uninitialized in this function [-Wmaybe-uninitialized]
137 | 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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |