# |
제출 시각 |
아이디 |
문제 |
언어 |
결과 |
실행 시간 |
메모리 |
128607 |
2019-07-11T07:21:34 Z |
구재현(#3166) |
영역 (JOI16_ho_t4) |
C++14 |
|
197 ms |
25884 KB |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
using lint = long long;
using pi = pair<lint, lint>;
int n, k;
char str[MAXN];
vector<pi> canon(vector<pi> v){
vector<pi> ev;
for(auto &i : v){
ev.emplace_back(i.first, +1);
ev.emplace_back(i.second + 1, -1);
}
sort(ev.begin(), ev.end());
vector<pi> ret;
int cnt = 0;
for(int i=0; i+1<ev.size(); i++){
cnt += ev[i].second;
if(ev[i].first != ev[i + 1].first){
if(cnt > 0){
ret.emplace_back(ev[i].first, ev[i + 1].first);
}
}
}
return ret;
}
lint getInsecLength(vector<pi> a, vector<pi> b, vector<pi> c, vector<pi> d){
vector<pi> ev;
for(auto &i : a){
ev.emplace_back(i.first, +1);
ev.emplace_back(i.second, -1);
}
for(auto &i : b){
ev.emplace_back(i.first, +1);
ev.emplace_back(i.second, -1);
}
for(auto &i : c){
ev.emplace_back(i.first, +1);
ev.emplace_back(i.second, -1);
}
for(auto &i : d){
ev.emplace_back(i.first, +1);
ev.emplace_back(i.second, -1);
}
sort(ev.begin(), ev.end());
int cnt = 0; lint ret = 0;
for(int i=0; i+1<ev.size(); i++){
cnt += ev[i].second;
if(ev[i].first != ev[i + 1].first){
if(cnt == 4){
ret += ev[i + 1].first - ev[i].first;
}
}
}
return ret;
}
int main(){
scanf("%d %d",&n,&k);
scanf("%s", str);
vector<pi> v = {pi(0, 0)};
lint px = 0, py = 0;
for(int j=0; j<n; j++){
if(str[j] == 'E') px++;
if(str[j] == 'W') px--;
if(str[j] == 'N') py++;
if(str[j] == 'S') py--;
v.emplace_back(px, py);
}
if(v.back().first < 0){
for(auto &i : v) i.first *= -1;
}
if(v.back().second < 0){
for(auto &i : v) i.second *= -1;
}
if(v.back().first == 0){
for(auto &i : v) swap(i.first, i.second);
}
if(v.back() == pi(0, 0)){
sort(v.begin(), v.end());
v.resize(unique(v.begin(), v.end()) - v.begin());
lint ret = 0;
for(auto &i : v){
if(binary_search(v.begin(), v.end(), pi(i.first + 1, i.second)) &&
binary_search(v.begin(), v.end(), pi(i.first, 1 + i.second)) &&
binary_search(v.begin(), v.end(), pi(i.first + 1, 1 + i.second))){
ret++;
}
}
cout << ret << endl;
return 0;
}
pi vect = v.back();
v.pop_back();
map<pi, vector<pi>> mp;
for(int i=0; i<v.size(); i++){
lint px = v[i].first;
lint py = v[i].second;
lint s = 0, e = k - 1;
if(i == 0) e = k;
if(px >= vect.first){
lint delta = px / vect.first;
px -= delta * vect.first;
py -= delta * vect.second;
s += delta;
e += delta;
}
if(px < 0){
lint delta = (vect.first - px - 1) / vect.first;
px += delta * vect.first;
py += delta * vect.second;
s -= delta;
e -= delta;
}
assert(px >= 0 && px < vect.first);
// printf("event %lld %lld = [%lld, %lld]\n", px, py, s, e);
mp[pi(px, py)].emplace_back(s, e);
}
for(auto &i : mp){
i.second = canon(i.second);
}
lint ret = 0;
for(auto &i : mp){
lint x, y; tie(x, y) = i.first;
auto n2 = pi(x, y + 1);
auto n3 = pi(x + 1, y);
auto n4 = pi(x + 1, y + 1);
if(x + 1 == vect.first){
n3.first -= vect.first;
n3.second -= vect.second;
n4.first -= vect.first;
n4.second -= vect.second;
}
if(mp.count(n2) && mp.count(n3) && mp.count(n4)){
auto i1 = i.second;
auto i2 = mp[n2];
auto i3 = mp[n3];
auto i4 = mp[n4];
if(x + 1 == vect.first){
for(auto &x : i3){
x.first--; x.second--;
}
for(auto &x : i4){
x.first--; x.second--;
}
}
ret += getInsecLength(i1, i2, i3, i4);
}
}
cout << ret << endl;
return 0;
}
Compilation message
2016_ho_t4.cpp: In function 'std::vector<std::pair<long long int, long long int> > canon(std::vector<std::pair<long long int, long long int> >)':
2016_ho_t4.cpp:19:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0; i+1<ev.size(); i++){
~~~^~~~~~~~~~
2016_ho_t4.cpp: In function 'lint getInsecLength(std::vector<std::pair<long long int, long long int> >, std::vector<std::pair<long long int, long long int> >, std::vector<std::pair<long long int, long long int> >, std::vector<std::pair<long long int, long long int> >)':
2016_ho_t4.cpp:50:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0; i+1<ev.size(); i++){
~~~^~~~~~~~~~
2016_ho_t4.cpp: In function 'int main()':
2016_ho_t4.cpp:100:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0; i<v.size(); i++){
~^~~~~~~~~
2016_ho_t4.cpp:63:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d",&n,&k);
~~~~~^~~~~~~~~~~~~~~
2016_ho_t4.cpp:64:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%s", str);
~~~~~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
256 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
256 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
256 KB |
Output is correct |
21 |
Correct |
2 ms |
256 KB |
Output is correct |
22 |
Correct |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
2 ms |
376 KB |
Output is correct |
24 |
Correct |
2 ms |
256 KB |
Output is correct |
25 |
Correct |
2 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
256 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
256 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
256 KB |
Output is correct |
21 |
Correct |
2 ms |
256 KB |
Output is correct |
22 |
Correct |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
2 ms |
376 KB |
Output is correct |
24 |
Correct |
2 ms |
256 KB |
Output is correct |
25 |
Correct |
2 ms |
256 KB |
Output is correct |
26 |
Correct |
2 ms |
376 KB |
Output is correct |
27 |
Correct |
4 ms |
632 KB |
Output is correct |
28 |
Correct |
4 ms |
760 KB |
Output is correct |
29 |
Correct |
31 ms |
3432 KB |
Output is correct |
30 |
Correct |
38 ms |
4140 KB |
Output is correct |
31 |
Correct |
79 ms |
11492 KB |
Output is correct |
32 |
Correct |
18 ms |
2540 KB |
Output is correct |
33 |
Correct |
64 ms |
6376 KB |
Output is correct |
34 |
Correct |
60 ms |
6372 KB |
Output is correct |
35 |
Correct |
60 ms |
6116 KB |
Output is correct |
36 |
Correct |
52 ms |
5348 KB |
Output is correct |
37 |
Correct |
18 ms |
2664 KB |
Output is correct |
38 |
Correct |
58 ms |
5988 KB |
Output is correct |
39 |
Correct |
65 ms |
6116 KB |
Output is correct |
40 |
Correct |
19 ms |
2664 KB |
Output is correct |
41 |
Correct |
47 ms |
4836 KB |
Output is correct |
42 |
Correct |
49 ms |
5476 KB |
Output is correct |
43 |
Correct |
64 ms |
6116 KB |
Output is correct |
44 |
Correct |
59 ms |
6244 KB |
Output is correct |
45 |
Correct |
54 ms |
5732 KB |
Output is correct |
46 |
Correct |
72 ms |
6756 KB |
Output is correct |
47 |
Correct |
122 ms |
9956 KB |
Output is correct |
48 |
Correct |
78 ms |
14208 KB |
Output is correct |
49 |
Correct |
98 ms |
12900 KB |
Output is correct |
50 |
Correct |
92 ms |
13028 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
256 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
256 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
256 KB |
Output is correct |
21 |
Correct |
2 ms |
256 KB |
Output is correct |
22 |
Correct |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
2 ms |
376 KB |
Output is correct |
24 |
Correct |
2 ms |
256 KB |
Output is correct |
25 |
Correct |
2 ms |
256 KB |
Output is correct |
26 |
Correct |
2 ms |
376 KB |
Output is correct |
27 |
Correct |
2 ms |
376 KB |
Output is correct |
28 |
Correct |
2 ms |
376 KB |
Output is correct |
29 |
Correct |
2 ms |
256 KB |
Output is correct |
30 |
Correct |
2 ms |
376 KB |
Output is correct |
31 |
Correct |
2 ms |
376 KB |
Output is correct |
32 |
Correct |
2 ms |
376 KB |
Output is correct |
33 |
Correct |
2 ms |
376 KB |
Output is correct |
34 |
Correct |
2 ms |
376 KB |
Output is correct |
35 |
Correct |
2 ms |
376 KB |
Output is correct |
36 |
Correct |
2 ms |
256 KB |
Output is correct |
37 |
Correct |
2 ms |
376 KB |
Output is correct |
38 |
Correct |
2 ms |
256 KB |
Output is correct |
39 |
Correct |
2 ms |
256 KB |
Output is correct |
40 |
Correct |
2 ms |
256 KB |
Output is correct |
41 |
Correct |
2 ms |
376 KB |
Output is correct |
42 |
Correct |
2 ms |
256 KB |
Output is correct |
43 |
Correct |
2 ms |
376 KB |
Output is correct |
44 |
Correct |
2 ms |
376 KB |
Output is correct |
45 |
Correct |
2 ms |
376 KB |
Output is correct |
46 |
Correct |
2 ms |
256 KB |
Output is correct |
47 |
Correct |
2 ms |
256 KB |
Output is correct |
48 |
Correct |
2 ms |
376 KB |
Output is correct |
49 |
Correct |
2 ms |
256 KB |
Output is correct |
50 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
256 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
256 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
256 KB |
Output is correct |
21 |
Correct |
2 ms |
256 KB |
Output is correct |
22 |
Correct |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
2 ms |
376 KB |
Output is correct |
24 |
Correct |
2 ms |
256 KB |
Output is correct |
25 |
Correct |
2 ms |
256 KB |
Output is correct |
26 |
Correct |
2 ms |
376 KB |
Output is correct |
27 |
Correct |
4 ms |
632 KB |
Output is correct |
28 |
Correct |
4 ms |
760 KB |
Output is correct |
29 |
Correct |
31 ms |
3432 KB |
Output is correct |
30 |
Correct |
38 ms |
4140 KB |
Output is correct |
31 |
Correct |
79 ms |
11492 KB |
Output is correct |
32 |
Correct |
18 ms |
2540 KB |
Output is correct |
33 |
Correct |
64 ms |
6376 KB |
Output is correct |
34 |
Correct |
60 ms |
6372 KB |
Output is correct |
35 |
Correct |
60 ms |
6116 KB |
Output is correct |
36 |
Correct |
52 ms |
5348 KB |
Output is correct |
37 |
Correct |
18 ms |
2664 KB |
Output is correct |
38 |
Correct |
58 ms |
5988 KB |
Output is correct |
39 |
Correct |
65 ms |
6116 KB |
Output is correct |
40 |
Correct |
19 ms |
2664 KB |
Output is correct |
41 |
Correct |
47 ms |
4836 KB |
Output is correct |
42 |
Correct |
49 ms |
5476 KB |
Output is correct |
43 |
Correct |
64 ms |
6116 KB |
Output is correct |
44 |
Correct |
59 ms |
6244 KB |
Output is correct |
45 |
Correct |
54 ms |
5732 KB |
Output is correct |
46 |
Correct |
72 ms |
6756 KB |
Output is correct |
47 |
Correct |
122 ms |
9956 KB |
Output is correct |
48 |
Correct |
78 ms |
14208 KB |
Output is correct |
49 |
Correct |
98 ms |
12900 KB |
Output is correct |
50 |
Correct |
92 ms |
13028 KB |
Output is correct |
51 |
Correct |
2 ms |
376 KB |
Output is correct |
52 |
Correct |
2 ms |
376 KB |
Output is correct |
53 |
Correct |
2 ms |
376 KB |
Output is correct |
54 |
Correct |
2 ms |
256 KB |
Output is correct |
55 |
Correct |
2 ms |
376 KB |
Output is correct |
56 |
Correct |
2 ms |
376 KB |
Output is correct |
57 |
Correct |
2 ms |
376 KB |
Output is correct |
58 |
Correct |
2 ms |
376 KB |
Output is correct |
59 |
Correct |
2 ms |
376 KB |
Output is correct |
60 |
Correct |
2 ms |
376 KB |
Output is correct |
61 |
Correct |
2 ms |
256 KB |
Output is correct |
62 |
Correct |
2 ms |
376 KB |
Output is correct |
63 |
Correct |
2 ms |
256 KB |
Output is correct |
64 |
Correct |
2 ms |
256 KB |
Output is correct |
65 |
Correct |
2 ms |
256 KB |
Output is correct |
66 |
Correct |
2 ms |
376 KB |
Output is correct |
67 |
Correct |
2 ms |
256 KB |
Output is correct |
68 |
Correct |
2 ms |
376 KB |
Output is correct |
69 |
Correct |
2 ms |
376 KB |
Output is correct |
70 |
Correct |
2 ms |
376 KB |
Output is correct |
71 |
Correct |
2 ms |
256 KB |
Output is correct |
72 |
Correct |
2 ms |
256 KB |
Output is correct |
73 |
Correct |
2 ms |
376 KB |
Output is correct |
74 |
Correct |
2 ms |
256 KB |
Output is correct |
75 |
Correct |
2 ms |
376 KB |
Output is correct |
76 |
Correct |
7 ms |
632 KB |
Output is correct |
77 |
Correct |
4 ms |
632 KB |
Output is correct |
78 |
Correct |
34 ms |
3324 KB |
Output is correct |
79 |
Correct |
47 ms |
6636 KB |
Output is correct |
80 |
Correct |
50 ms |
4324 KB |
Output is correct |
81 |
Correct |
19 ms |
2664 KB |
Output is correct |
82 |
Correct |
57 ms |
5988 KB |
Output is correct |
83 |
Correct |
47 ms |
4836 KB |
Output is correct |
84 |
Correct |
61 ms |
6244 KB |
Output is correct |
85 |
Correct |
62 ms |
6116 KB |
Output is correct |
86 |
Correct |
149 ms |
18804 KB |
Output is correct |
87 |
Correct |
67 ms |
6500 KB |
Output is correct |
88 |
Correct |
57 ms |
5864 KB |
Output is correct |
89 |
Correct |
60 ms |
5860 KB |
Output is correct |
90 |
Correct |
19 ms |
2668 KB |
Output is correct |
91 |
Correct |
63 ms |
6352 KB |
Output is correct |
92 |
Correct |
63 ms |
6376 KB |
Output is correct |
93 |
Correct |
61 ms |
6164 KB |
Output is correct |
94 |
Correct |
53 ms |
5476 KB |
Output is correct |
95 |
Correct |
55 ms |
5476 KB |
Output is correct |
96 |
Correct |
79 ms |
6820 KB |
Output is correct |
97 |
Correct |
119 ms |
9956 KB |
Output is correct |
98 |
Correct |
152 ms |
25884 KB |
Output is correct |
99 |
Correct |
83 ms |
13028 KB |
Output is correct |
100 |
Correct |
197 ms |
13024 KB |
Output is correct |