# |
제출 시각 |
아이디 |
문제 |
언어 |
결과 |
실행 시간 |
메모리 |
128583 |
2019-07-11T07:09:19 Z |
김세빈(#3158) |
영역 (JOI16_ho_t4) |
C++14 |
|
117 ms |
20196 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <ll, ll> pll;
vector <pll> V[101010], X;
set <pll> S[101010], T;
pll P[101010];
char C[101010];
ll dx[3] = {1, 0, 1}, dy[3] = {0, 1, 1};
ll n, k, a, b, z, ans;
ll gcd(ll p, ll q) { for(; p; swap(p, q)) q %= p; return q; }
pll getcoor(pll p) {
return pll(b * p.first - a * p.second, a * p.first + b * p.second); }
void insert(set <pll> &S, ll l, ll r)
{
auto it = S.lower_bound(pll(l, -1e18));
if(it != S.begin() && prev(it) -> second >= l){
l = prev(it) -> first; r = max(r, prev(it) -> second);
S.erase(prev(it));
}
for(; ; ){
it = S.lower_bound(pll(l, -1e18));
if(it == S.end() || r < it -> first) break;
r = max(r, it -> second); S.erase(it);
}
S.insert(pll(l, r));
}
void findintv(ll x, ll y, ll l, ll r, ll d, set <pll> &T)
{
if(l >= r) return;
else if(d == 3) insert(T, l, r);
else{
pll p = getcoor(pll(x + dx[d], y + dy[d])), _p = p; _p.second %= z;
ll t = lower_bound(X.begin(), X.end(), _p) - X.begin();
if(t == X.size() || X[t] != _p) return;
ll f = getcoor(pll(x, y)).second / z - p.second / z;
auto it = S[t].lower_bound(pll(l - f, -1e18));
if(it != S[t].begin() && prev(it) -> second + f >= l){
if(prev(it) -> second + f >= r) findintv(x, y, l, r, d + 1, T);
else findintv(x, y, l, prev(it) -> second + f, d + 1, T);
}
if(it != S[t].end() && it -> first + f <= r){
findintv(x, y, it -> first + f, r, d + 1, T);
}
}
}
int main()
{
ll i, j, x, y, g, l, r, t;
scanf("%lld%lld%s", &n, &k, C);
for(i=0, x=0, y=0; i<n; i++){
P[i] = pll(x, y);
if(C[i] == 'N') y ++;
else if(C[i] == 'S') y --;
else if(C[i] == 'E') x ++;
else x --;
}
P[i] = pll(x, y);
if(x < 0){
for(i=0; i<=n; i++){
P[i].first = -P[i].first;
}
x = -x;
}
if(y < 0){
for(i=0; i<=n; i++){
P[i].second = -P[i].second;
}
y = -y;
}
if(x == 0 && y == 0){
x = 1; k = 1;
}
g = gcd(x, y);
a = x / g; b = y / g;
z = g * (a * a + b * b);
for(i=0; i<=n; i++){
tie(x, y) = getcoor(P[i]);
X.emplace_back(x, y % z);
}
sort(X.begin(), X.end());
X.erase(unique(X.begin(), X.end()), X.end());
for(i=0; i<=n; i++){
tie(x, y) = getcoor(P[i]); y %= z;
t = lower_bound(X.begin(), X.end(), pll(x, y)) - X.begin();
V[t].push_back(P[i]);
}
for(i=0; i<X.size(); i++){
for(pll &p: V[i]){
l = getcoor(p).second / z;
r = l + k;
insert(S[i], l, r);
}
}
for(i=0; i<X.size(); i++){
T.clear();
for(pll &p: V[i]){
l = getcoor(p).second / z;
r = l + k;
findintv(p.first, p.second, l, r, 0, T);
}
for(pll p: T){
ans += p.second - p.first;
}
}
printf("%lld\n", ans);
return 0;
}
Compilation message
2016_ho_t4.cpp: In function 'void findintv(ll, ll, ll, ll, ll, std::set<std::pair<long long int, long long int> >&)':
2016_ho_t4.cpp:44:8: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(t == X.size() || X[t] != _p) return;
~~^~~~~~~~~~~
2016_ho_t4.cpp: In function 'int main()':
2016_ho_t4.cpp:112:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(i=0; i<X.size(); i++){
~^~~~~~~~~
2016_ho_t4.cpp:120:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(i=0; i<X.size(); i++){
~^~~~~~~~~
2016_ho_t4.cpp:61:8: warning: unused variable 'j' [-Wunused-variable]
ll i, j, x, y, g, l, r, t;
^
2016_ho_t4.cpp:63:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld%lld%s", &n, &k, C);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
7416 KB |
Output is correct |
2 |
Correct |
9 ms |
7420 KB |
Output is correct |
3 |
Correct |
8 ms |
7416 KB |
Output is correct |
4 |
Correct |
8 ms |
7416 KB |
Output is correct |
5 |
Correct |
8 ms |
7416 KB |
Output is correct |
6 |
Correct |
8 ms |
7420 KB |
Output is correct |
7 |
Correct |
10 ms |
7416 KB |
Output is correct |
8 |
Correct |
10 ms |
7416 KB |
Output is correct |
9 |
Correct |
8 ms |
7416 KB |
Output is correct |
10 |
Correct |
9 ms |
7416 KB |
Output is correct |
11 |
Correct |
8 ms |
7420 KB |
Output is correct |
12 |
Correct |
8 ms |
7416 KB |
Output is correct |
13 |
Correct |
11 ms |
7416 KB |
Output is correct |
14 |
Correct |
9 ms |
7416 KB |
Output is correct |
15 |
Correct |
9 ms |
7432 KB |
Output is correct |
16 |
Correct |
10 ms |
7416 KB |
Output is correct |
17 |
Correct |
9 ms |
7416 KB |
Output is correct |
18 |
Correct |
10 ms |
7416 KB |
Output is correct |
19 |
Correct |
8 ms |
7416 KB |
Output is correct |
20 |
Correct |
8 ms |
7416 KB |
Output is correct |
21 |
Correct |
8 ms |
7416 KB |
Output is correct |
22 |
Correct |
10 ms |
7416 KB |
Output is correct |
23 |
Correct |
8 ms |
7416 KB |
Output is correct |
24 |
Correct |
8 ms |
7416 KB |
Output is correct |
25 |
Correct |
8 ms |
7388 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
7416 KB |
Output is correct |
2 |
Correct |
9 ms |
7420 KB |
Output is correct |
3 |
Correct |
8 ms |
7416 KB |
Output is correct |
4 |
Correct |
8 ms |
7416 KB |
Output is correct |
5 |
Correct |
8 ms |
7416 KB |
Output is correct |
6 |
Correct |
8 ms |
7420 KB |
Output is correct |
7 |
Correct |
10 ms |
7416 KB |
Output is correct |
8 |
Correct |
10 ms |
7416 KB |
Output is correct |
9 |
Correct |
8 ms |
7416 KB |
Output is correct |
10 |
Correct |
9 ms |
7416 KB |
Output is correct |
11 |
Correct |
8 ms |
7420 KB |
Output is correct |
12 |
Correct |
8 ms |
7416 KB |
Output is correct |
13 |
Correct |
11 ms |
7416 KB |
Output is correct |
14 |
Correct |
9 ms |
7416 KB |
Output is correct |
15 |
Correct |
9 ms |
7432 KB |
Output is correct |
16 |
Correct |
10 ms |
7416 KB |
Output is correct |
17 |
Correct |
9 ms |
7416 KB |
Output is correct |
18 |
Correct |
10 ms |
7416 KB |
Output is correct |
19 |
Correct |
8 ms |
7416 KB |
Output is correct |
20 |
Correct |
8 ms |
7416 KB |
Output is correct |
21 |
Correct |
8 ms |
7416 KB |
Output is correct |
22 |
Correct |
10 ms |
7416 KB |
Output is correct |
23 |
Correct |
8 ms |
7416 KB |
Output is correct |
24 |
Correct |
8 ms |
7416 KB |
Output is correct |
25 |
Correct |
8 ms |
7388 KB |
Output is correct |
26 |
Correct |
11 ms |
7544 KB |
Output is correct |
27 |
Correct |
31 ms |
7800 KB |
Output is correct |
28 |
Correct |
17 ms |
8436 KB |
Output is correct |
29 |
Correct |
44 ms |
11244 KB |
Output is correct |
30 |
Correct |
61 ms |
12388 KB |
Output is correct |
31 |
Correct |
67 ms |
18916 KB |
Output is correct |
32 |
Correct |
69 ms |
13028 KB |
Output is correct |
33 |
Correct |
86 ms |
14564 KB |
Output is correct |
34 |
Correct |
85 ms |
14692 KB |
Output is correct |
35 |
Correct |
85 ms |
14564 KB |
Output is correct |
36 |
Correct |
83 ms |
13924 KB |
Output is correct |
37 |
Correct |
68 ms |
13080 KB |
Output is correct |
38 |
Correct |
86 ms |
14536 KB |
Output is correct |
39 |
Correct |
83 ms |
14644 KB |
Output is correct |
40 |
Correct |
117 ms |
13156 KB |
Output is correct |
41 |
Correct |
77 ms |
13668 KB |
Output is correct |
42 |
Correct |
81 ms |
13924 KB |
Output is correct |
43 |
Correct |
85 ms |
14692 KB |
Output is correct |
44 |
Correct |
84 ms |
14436 KB |
Output is correct |
45 |
Correct |
80 ms |
14180 KB |
Output is correct |
46 |
Correct |
63 ms |
15844 KB |
Output is correct |
47 |
Correct |
75 ms |
16228 KB |
Output is correct |
48 |
Correct |
39 ms |
13028 KB |
Output is correct |
49 |
Correct |
49 ms |
20196 KB |
Output is correct |
50 |
Correct |
62 ms |
20196 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
7416 KB |
Output is correct |
2 |
Correct |
9 ms |
7420 KB |
Output is correct |
3 |
Correct |
8 ms |
7416 KB |
Output is correct |
4 |
Correct |
8 ms |
7416 KB |
Output is correct |
5 |
Correct |
8 ms |
7416 KB |
Output is correct |
6 |
Correct |
8 ms |
7420 KB |
Output is correct |
7 |
Correct |
10 ms |
7416 KB |
Output is correct |
8 |
Correct |
10 ms |
7416 KB |
Output is correct |
9 |
Correct |
8 ms |
7416 KB |
Output is correct |
10 |
Correct |
9 ms |
7416 KB |
Output is correct |
11 |
Correct |
8 ms |
7420 KB |
Output is correct |
12 |
Correct |
8 ms |
7416 KB |
Output is correct |
13 |
Correct |
11 ms |
7416 KB |
Output is correct |
14 |
Correct |
9 ms |
7416 KB |
Output is correct |
15 |
Correct |
9 ms |
7432 KB |
Output is correct |
16 |
Correct |
10 ms |
7416 KB |
Output is correct |
17 |
Correct |
9 ms |
7416 KB |
Output is correct |
18 |
Correct |
10 ms |
7416 KB |
Output is correct |
19 |
Correct |
8 ms |
7416 KB |
Output is correct |
20 |
Correct |
8 ms |
7416 KB |
Output is correct |
21 |
Correct |
8 ms |
7416 KB |
Output is correct |
22 |
Correct |
10 ms |
7416 KB |
Output is correct |
23 |
Correct |
8 ms |
7416 KB |
Output is correct |
24 |
Correct |
8 ms |
7416 KB |
Output is correct |
25 |
Correct |
8 ms |
7388 KB |
Output is correct |
26 |
Incorrect |
8 ms |
7416 KB |
Output isn't correct |
27 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
7416 KB |
Output is correct |
2 |
Correct |
9 ms |
7420 KB |
Output is correct |
3 |
Correct |
8 ms |
7416 KB |
Output is correct |
4 |
Correct |
8 ms |
7416 KB |
Output is correct |
5 |
Correct |
8 ms |
7416 KB |
Output is correct |
6 |
Correct |
8 ms |
7420 KB |
Output is correct |
7 |
Correct |
10 ms |
7416 KB |
Output is correct |
8 |
Correct |
10 ms |
7416 KB |
Output is correct |
9 |
Correct |
8 ms |
7416 KB |
Output is correct |
10 |
Correct |
9 ms |
7416 KB |
Output is correct |
11 |
Correct |
8 ms |
7420 KB |
Output is correct |
12 |
Correct |
8 ms |
7416 KB |
Output is correct |
13 |
Correct |
11 ms |
7416 KB |
Output is correct |
14 |
Correct |
9 ms |
7416 KB |
Output is correct |
15 |
Correct |
9 ms |
7432 KB |
Output is correct |
16 |
Correct |
10 ms |
7416 KB |
Output is correct |
17 |
Correct |
9 ms |
7416 KB |
Output is correct |
18 |
Correct |
10 ms |
7416 KB |
Output is correct |
19 |
Correct |
8 ms |
7416 KB |
Output is correct |
20 |
Correct |
8 ms |
7416 KB |
Output is correct |
21 |
Correct |
8 ms |
7416 KB |
Output is correct |
22 |
Correct |
10 ms |
7416 KB |
Output is correct |
23 |
Correct |
8 ms |
7416 KB |
Output is correct |
24 |
Correct |
8 ms |
7416 KB |
Output is correct |
25 |
Correct |
8 ms |
7388 KB |
Output is correct |
26 |
Correct |
11 ms |
7544 KB |
Output is correct |
27 |
Correct |
31 ms |
7800 KB |
Output is correct |
28 |
Correct |
17 ms |
8436 KB |
Output is correct |
29 |
Correct |
44 ms |
11244 KB |
Output is correct |
30 |
Correct |
61 ms |
12388 KB |
Output is correct |
31 |
Correct |
67 ms |
18916 KB |
Output is correct |
32 |
Correct |
69 ms |
13028 KB |
Output is correct |
33 |
Correct |
86 ms |
14564 KB |
Output is correct |
34 |
Correct |
85 ms |
14692 KB |
Output is correct |
35 |
Correct |
85 ms |
14564 KB |
Output is correct |
36 |
Correct |
83 ms |
13924 KB |
Output is correct |
37 |
Correct |
68 ms |
13080 KB |
Output is correct |
38 |
Correct |
86 ms |
14536 KB |
Output is correct |
39 |
Correct |
83 ms |
14644 KB |
Output is correct |
40 |
Correct |
117 ms |
13156 KB |
Output is correct |
41 |
Correct |
77 ms |
13668 KB |
Output is correct |
42 |
Correct |
81 ms |
13924 KB |
Output is correct |
43 |
Correct |
85 ms |
14692 KB |
Output is correct |
44 |
Correct |
84 ms |
14436 KB |
Output is correct |
45 |
Correct |
80 ms |
14180 KB |
Output is correct |
46 |
Correct |
63 ms |
15844 KB |
Output is correct |
47 |
Correct |
75 ms |
16228 KB |
Output is correct |
48 |
Correct |
39 ms |
13028 KB |
Output is correct |
49 |
Correct |
49 ms |
20196 KB |
Output is correct |
50 |
Correct |
62 ms |
20196 KB |
Output is correct |
51 |
Incorrect |
8 ms |
7416 KB |
Output isn't correct |
52 |
Halted |
0 ms |
0 KB |
- |