Submission #1000993
Source Code Expand
#include <cstdio>
#include <cassert>
#include <algorithm>
using namespace std;
const int N = 1050;
struct vt {
int x, y;
vt(int _x, int _y) {
x = _x, y = _y;
}
vt() {}
friend vt operator +(vt a, vt b) {
return vt(a.x + b.x, a.y + b.y);
}
friend vt operator -(vt a, vt b) {
return vt(a.x - b.x, a.y - b.y);
}
friend vt operator ~(vt v) {
return vt(-v.y, v.x);
}
friend int operator *(vt a, vt b) {
return a.x * b.x + a.y * b.y;
}
int l1abs() {
return abs(x) + abs(y);
}
vt norm() {
int l = l1abs();
return vt(x / l, y / l);
}
friend bool operator ==(vt a, vt b) {
return a.x == b.x && a.y == b.y;
}
};
vector<char> S;
vector<vt> P;
int m;
inline void shift(vt dir, vt as) {
for (int i = 0; i < m; i++) {
if ((P[i] - as) * dir >= 0)
P[i] = P[i] + dir;
}
}
int tp[N];
// 0 - LR
// 1 - RL
int oper[N];
bool in_seg(int a, int b, int c) {
return a <= b && b <= c;
}
bool inter(vt a, vt b, vt c, vt d) {
if (a.y == b.y)
swap(a, c), swap(b, d);
return in_seg(a.y, c.y, b.y) && in_seg(c.x, a.x, d.x);
}
vector<char> orig_S;
void check() {
for (int i = 0; i < m; i++) {
vt a = P[i], b = P[(i + 1) % m], c = P[(i + 2) % m];
vt u = (b - a).norm();
vt v = (c - b).norm();
if (S[i] == 'L')
assert(~u == v);
else
assert(~v == u);
}
for (int i = 0; i < m; i += 2) {
for (int j = 1; j < m; j += 2) {
if (abs(i - j) <= 1)
continue;
if (i == 0 && j == m - 1)
continue;
assert(!inter(P[i], P[(i + 1) % m], P[j % m], P[(j + 1) % m]));
}
}
}
int main() {
int n;
scanf("%d", &n);
int bal = 0;
S.resize(n);
for (int i = 0; i < n; i++) {
int x;
scanf("%d", &x);
S[i] = "RL"[x == 90];
bal += (S[i] == 'L') - (S[i] == 'R');
}
orig_S = S;
if (bal != 4) {
puts("-1");
return 0;
}
m = n;
int pt = 0;
while (m > 4) {
bool found = false;
for (int i = 0; i < m - 1; i++) {
if (S[i] != S[i + 1]) {
tp[pt] = S[i] == 'R';
oper[pt] = i;
pt++;
found = true;
break;
}
}
assert(found);
int pos = oper[pt - 1];
S.erase(S.begin() + pos, S.begin() + pos + 2);
m -= 2;
}
P = { vt(0, 0), vt(1, 0), vt(1, 1), vt(0, 1) };
check();
while ((--pt) >= 0) {
int pos = oper[pt];
// LR
vt v = P[(pos + 1) % m] - P[pos % m];
v = v.norm();
vt u = (tp[pt] == 0) ? ~v : ~~~v;
shift(v, P[(pos + 1) % m]);
assert((P[(pos + 1) % m] - P[pos % m]).l1abs() >= 2);
shift(u, P[pos % m] + u);
P[(pos + 1) % m] = P[(pos + 1) % m] + u;
P.insert(P.begin() + pos % m + 1, P[pos % m] + v);
P.insert(P.begin() + pos % m + 2, P[pos % m] + v + u);
S.insert(S.begin() + pos, (tp[pt] == 0 ? 'L' : 'R'));
S.insert(S.begin() + pos + 1, (tp[pt] == 0 ? 'R' : 'L'));
if (pos == m) {
rotate(P.begin(), P.begin() + 2, P.end());
}
m += 2;
//check();
}
assert(S == orig_S);
check();
rotate(P.begin(), P.begin() + 1, P.end());
int mnx = 0;
int mny = 0;
for (auto p : P)
mnx = min(mnx, p.x), mny = min(mny, p.y);
for (auto& p : P)
p.x -= mnx, p.y -= mny;
for (auto p : P)
printf("%d %d\n", p.x, p.y);
}
Submission Info
Submission Time |
|
Task |
I - 90 and 270 |
User |
Zlobober |
Language |
C++14 (GCC 5.4.1) |
Score |
1500 |
Code Size |
3819 Byte |
Status |
AC |
Exec Time |
9 ms |
Memory |
256 KB |
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:90:20: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &n);
^
./Main.cpp:95:24: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &x);
^
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
1500 / 1500 |
Status |
|
|
Set Name |
Test Cases |
Sample |
example0.txt, example1.txt |
All |
000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, 024.txt, 025.txt, 026.txt, 027.txt, 028.txt, 029.txt, 030.txt, 031.txt, 032.txt, 033.txt, 034.txt, 035.txt, 036.txt, 037.txt, 038.txt, 039.txt, 040.txt, 041.txt, 042.txt, 043.txt, example0.txt, example1.txt |
Case Name |
Status |
Exec Time |
Memory |
000.txt |
AC |
2 ms |
256 KB |
001.txt |
AC |
2 ms |
256 KB |
002.txt |
AC |
2 ms |
256 KB |
003.txt |
AC |
4 ms |
256 KB |
004.txt |
AC |
3 ms |
256 KB |
005.txt |
AC |
3 ms |
256 KB |
006.txt |
AC |
4 ms |
256 KB |
007.txt |
AC |
3 ms |
256 KB |
008.txt |
AC |
3 ms |
256 KB |
009.txt |
AC |
3 ms |
256 KB |
010.txt |
AC |
5 ms |
256 KB |
011.txt |
AC |
2 ms |
256 KB |
012.txt |
AC |
4 ms |
256 KB |
013.txt |
AC |
4 ms |
256 KB |
014.txt |
AC |
3 ms |
256 KB |
015.txt |
AC |
3 ms |
256 KB |
016.txt |
AC |
4 ms |
256 KB |
017.txt |
AC |
2 ms |
256 KB |
018.txt |
AC |
4 ms |
256 KB |
019.txt |
AC |
3 ms |
256 KB |
020.txt |
AC |
6 ms |
256 KB |
021.txt |
AC |
2 ms |
256 KB |
022.txt |
AC |
6 ms |
256 KB |
023.txt |
AC |
9 ms |
256 KB |
024.txt |
AC |
7 ms |
256 KB |
025.txt |
AC |
7 ms |
256 KB |
026.txt |
AC |
7 ms |
256 KB |
027.txt |
AC |
7 ms |
256 KB |
028.txt |
AC |
7 ms |
256 KB |
029.txt |
AC |
7 ms |
256 KB |
030.txt |
AC |
7 ms |
256 KB |
031.txt |
AC |
7 ms |
256 KB |
032.txt |
AC |
7 ms |
256 KB |
033.txt |
AC |
7 ms |
256 KB |
034.txt |
AC |
7 ms |
256 KB |
035.txt |
AC |
7 ms |
256 KB |
036.txt |
AC |
7 ms |
256 KB |
037.txt |
AC |
7 ms |
256 KB |
038.txt |
AC |
7 ms |
256 KB |
039.txt |
AC |
7 ms |
256 KB |
040.txt |
AC |
7 ms |
256 KB |
041.txt |
AC |
7 ms |
256 KB |
042.txt |
AC |
7 ms |
256 KB |
043.txt |
AC |
2 ms |
256 KB |
example0.txt |
AC |
2 ms |
256 KB |
example1.txt |
AC |
2 ms |
256 KB |