이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <cstdio>
#include <algorithm>
#define N 1000005
#define F first
#define S second
using namespace std;
int n, sz, st, m, cnt, s1, s2, mx, mn = 2e9, rs, x[N], y[N], a[N];
struct str {
int c, z, num;
} b[N];
bool comp(str p, str q) {
return p.c < q.c;
}
int main()
{
int i, j;
cin >> n;
sz = st = 1;
for (i = 0; i < n; i++) {
scanf ("%d %d", &x[i], &y[i]);
if (x[i] < mn) {
mn = x[i];
rs = i;
}
}
for (j = 0, i = rs; j < n; j++, i = (i + 1) % n) {
if (y[i] > 0 && y[(i - 1 + n) % n] < 0 || y[i] < 0 && y[(i - 1 + n) % n] > 0) a[sz++] = x[i];
}
if (y[rs] > 0) {
st = 0;
a[0] = a[sz - 1];
sz--;
}
for (i = st, j = 1; i < sz; i += 2, j++) {
if (a[i] > a[i + 1]) swap(a[i], a[i + 1]);
b[m].c = a[i];
b[m + 1].c = a[i + 1];
b[m].z = 1;
b[m + 1].z = 2;
b[m].num = j;
b[m + 1].num = j;
m += 2;
}
sort(b, b + m, comp);
mx = -2e9;
for (i = 0; i < m; i++) {
if (b[i].z == 1) {
cnt++;
if (cnt == 1) s1++;
if (b[i + 1].z == 2 && b[i + 1].num == b[i].num) s2++;
} else cnt--;
}
cout << s1 << " " << s2;
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
cut.cpp: In function 'int main()':
cut.cpp:30:16: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
if (y[i] > 0 && y[(i - 1 + n) % n] < 0 || y[i] < 0 && y[(i - 1 + n) % n] > 0) a[sz++] = x[i];
~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
cut.cpp:23:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf ("%d %d", &x[i], &y[i]);
~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |