# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
128589 |
2019-07-11T07:14:05 Z |
김세빈(#3158) |
None (JOI16_ho_t4) |
C++14 |
|
95 ms |
20068 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(pll p: S[i]) if(p.second - p.first < k) for(; ; );
}
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:122: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);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
7416 KB |
Output is correct |
2 |
Correct |
8 ms |
7416 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 |
7416 KB |
Output is correct |
7 |
Correct |
8 ms |
7416 KB |
Output is correct |
8 |
Correct |
9 ms |
7416 KB |
Output is correct |
9 |
Correct |
8 ms |
7416 KB |
Output is correct |
10 |
Correct |
10 ms |
7416 KB |
Output is correct |
11 |
Correct |
10 ms |
7416 KB |
Output is correct |
12 |
Correct |
8 ms |
7416 KB |
Output is correct |
13 |
Correct |
8 ms |
7416 KB |
Output is correct |
14 |
Correct |
10 ms |
7416 KB |
Output is correct |
15 |
Correct |
8 ms |
7416 KB |
Output is correct |
16 |
Correct |
10 ms |
7416 KB |
Output is correct |
17 |
Correct |
9 ms |
7416 KB |
Output is correct |
18 |
Correct |
8 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 |
8 ms |
7416 KB |
Output is correct |
23 |
Correct |
8 ms |
7432 KB |
Output is correct |
24 |
Correct |
8 ms |
7420 KB |
Output is correct |
25 |
Correct |
8 ms |
7420 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
7416 KB |
Output is correct |
2 |
Correct |
8 ms |
7416 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 |
7416 KB |
Output is correct |
7 |
Correct |
8 ms |
7416 KB |
Output is correct |
8 |
Correct |
9 ms |
7416 KB |
Output is correct |
9 |
Correct |
8 ms |
7416 KB |
Output is correct |
10 |
Correct |
10 ms |
7416 KB |
Output is correct |
11 |
Correct |
10 ms |
7416 KB |
Output is correct |
12 |
Correct |
8 ms |
7416 KB |
Output is correct |
13 |
Correct |
8 ms |
7416 KB |
Output is correct |
14 |
Correct |
10 ms |
7416 KB |
Output is correct |
15 |
Correct |
8 ms |
7416 KB |
Output is correct |
16 |
Correct |
10 ms |
7416 KB |
Output is correct |
17 |
Correct |
9 ms |
7416 KB |
Output is correct |
18 |
Correct |
8 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 |
8 ms |
7416 KB |
Output is correct |
23 |
Correct |
8 ms |
7432 KB |
Output is correct |
24 |
Correct |
8 ms |
7420 KB |
Output is correct |
25 |
Correct |
8 ms |
7420 KB |
Output is correct |
26 |
Correct |
8 ms |
7544 KB |
Output is correct |
27 |
Correct |
12 ms |
7800 KB |
Output is correct |
28 |
Correct |
17 ms |
8304 KB |
Output is correct |
29 |
Correct |
46 ms |
11196 KB |
Output is correct |
30 |
Correct |
70 ms |
12388 KB |
Output is correct |
31 |
Correct |
75 ms |
18788 KB |
Output is correct |
32 |
Correct |
68 ms |
12900 KB |
Output is correct |
33 |
Correct |
86 ms |
14692 KB |
Output is correct |
34 |
Correct |
84 ms |
14696 KB |
Output is correct |
35 |
Correct |
85 ms |
14564 KB |
Output is correct |
36 |
Correct |
83 ms |
14040 KB |
Output is correct |
37 |
Correct |
68 ms |
13020 KB |
Output is correct |
38 |
Correct |
85 ms |
14564 KB |
Output is correct |
39 |
Correct |
83 ms |
14564 KB |
Output is correct |
40 |
Correct |
68 ms |
13128 KB |
Output is correct |
41 |
Correct |
79 ms |
13672 KB |
Output is correct |
42 |
Correct |
80 ms |
13928 KB |
Output is correct |
43 |
Correct |
95 ms |
14564 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 |
74 ms |
16196 KB |
Output is correct |
48 |
Correct |
40 ms |
13032 KB |
Output is correct |
49 |
Correct |
49 ms |
20068 KB |
Output is correct |
50 |
Correct |
63 ms |
20068 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
7416 KB |
Output is correct |
2 |
Correct |
8 ms |
7416 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 |
7416 KB |
Output is correct |
7 |
Correct |
8 ms |
7416 KB |
Output is correct |
8 |
Correct |
9 ms |
7416 KB |
Output is correct |
9 |
Correct |
8 ms |
7416 KB |
Output is correct |
10 |
Correct |
10 ms |
7416 KB |
Output is correct |
11 |
Correct |
10 ms |
7416 KB |
Output is correct |
12 |
Correct |
8 ms |
7416 KB |
Output is correct |
13 |
Correct |
8 ms |
7416 KB |
Output is correct |
14 |
Correct |
10 ms |
7416 KB |
Output is correct |
15 |
Correct |
8 ms |
7416 KB |
Output is correct |
16 |
Correct |
10 ms |
7416 KB |
Output is correct |
17 |
Correct |
9 ms |
7416 KB |
Output is correct |
18 |
Correct |
8 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 |
8 ms |
7416 KB |
Output is correct |
23 |
Correct |
8 ms |
7432 KB |
Output is correct |
24 |
Correct |
8 ms |
7420 KB |
Output is correct |
25 |
Correct |
8 ms |
7420 KB |
Output is correct |
26 |
Incorrect |
9 ms |
7544 KB |
Output isn't correct |
27 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
7416 KB |
Output is correct |
2 |
Correct |
8 ms |
7416 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 |
7416 KB |
Output is correct |
7 |
Correct |
8 ms |
7416 KB |
Output is correct |
8 |
Correct |
9 ms |
7416 KB |
Output is correct |
9 |
Correct |
8 ms |
7416 KB |
Output is correct |
10 |
Correct |
10 ms |
7416 KB |
Output is correct |
11 |
Correct |
10 ms |
7416 KB |
Output is correct |
12 |
Correct |
8 ms |
7416 KB |
Output is correct |
13 |
Correct |
8 ms |
7416 KB |
Output is correct |
14 |
Correct |
10 ms |
7416 KB |
Output is correct |
15 |
Correct |
8 ms |
7416 KB |
Output is correct |
16 |
Correct |
10 ms |
7416 KB |
Output is correct |
17 |
Correct |
9 ms |
7416 KB |
Output is correct |
18 |
Correct |
8 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 |
8 ms |
7416 KB |
Output is correct |
23 |
Correct |
8 ms |
7432 KB |
Output is correct |
24 |
Correct |
8 ms |
7420 KB |
Output is correct |
25 |
Correct |
8 ms |
7420 KB |
Output is correct |
26 |
Correct |
8 ms |
7544 KB |
Output is correct |
27 |
Correct |
12 ms |
7800 KB |
Output is correct |
28 |
Correct |
17 ms |
8304 KB |
Output is correct |
29 |
Correct |
46 ms |
11196 KB |
Output is correct |
30 |
Correct |
70 ms |
12388 KB |
Output is correct |
31 |
Correct |
75 ms |
18788 KB |
Output is correct |
32 |
Correct |
68 ms |
12900 KB |
Output is correct |
33 |
Correct |
86 ms |
14692 KB |
Output is correct |
34 |
Correct |
84 ms |
14696 KB |
Output is correct |
35 |
Correct |
85 ms |
14564 KB |
Output is correct |
36 |
Correct |
83 ms |
14040 KB |
Output is correct |
37 |
Correct |
68 ms |
13020 KB |
Output is correct |
38 |
Correct |
85 ms |
14564 KB |
Output is correct |
39 |
Correct |
83 ms |
14564 KB |
Output is correct |
40 |
Correct |
68 ms |
13128 KB |
Output is correct |
41 |
Correct |
79 ms |
13672 KB |
Output is correct |
42 |
Correct |
80 ms |
13928 KB |
Output is correct |
43 |
Correct |
95 ms |
14564 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 |
74 ms |
16196 KB |
Output is correct |
48 |
Correct |
40 ms |
13032 KB |
Output is correct |
49 |
Correct |
49 ms |
20068 KB |
Output is correct |
50 |
Correct |
63 ms |
20068 KB |
Output is correct |
51 |
Incorrect |
9 ms |
7544 KB |
Output isn't correct |
52 |
Halted |
0 ms |
0 KB |
- |