# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
874174 |
2023-11-16T11:53:00 Z |
garam1732 |
None (JOI16_ho_t4) |
C++14 |
|
1000 ms |
12368 KB |
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define bl " "
#define endl "\n"
#define all(v) v.begin(), v.end()
#define comp(v) v.erase(unique(all(v)), v.end())
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<pi, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 100100;
const int MOD = 1e9+7;
set<pi> s, ps;
vector<pi> arr[MAXN], u;
vector<pll> w;
vector<int> ww;
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
int n, k; cin >> n >> k;
string str; cin >> str;
pll v = pll(0, 0); s.insert(v);
for(int i = 0; i < n; i++) {
if(str[i] == 'N') v.ss++;
else if(str[i] == 'S') v.ss--;
else if(str[i] == 'E') v.ff++;
else v.ff--;
s.insert(v);
}
if(v == pll(0, 0) || k == 1) {
int cnt = 0;
for(auto x : s) {
if(s.count(pi(x.ff+1,x.ss)) && s.count(pi(x.ff,x.ss+1)) && s.count(pi(x.ff+1, x.ss+1)))
cnt++;
}
cout << cnt;
return 0;
}
if(v.ff == 0) {
for(auto x : s) ps.insert(pi(x.ss, x.ff));
swap(v.ff, v.ss);
swap(s, ps); ps.clear();
}
if(v.ff < 0) {
for(auto x : s) ps.insert(pi(-x.ff, x.ss));
v.ff = -v.ff;
swap(s, ps); ps.clear();
}
for(auto x : s) w.push_back(pll(v.ff*x.ss-v.ss*x.ff, (x.ff%v.ff+v.ff)%v.ff));
sort(all(w)); comp(w);
for(auto x : s) {
int it = lower_bound(all(w), pll(v.ff*x.ss-v.ss*x.ff, (x.ff%v.ff+v.ff)%v.ff)) - w.begin();
arr[it].push_back(pi(x.ff, k-1));
}
for(int i = 0; i < w.size(); i++) {
sort(all(arr[i]));
//cout<<endl;
for(auto y : arr[i]) {
// cout<<'a'<<y.ff<<bl<<y.ss<<bl;
if(u.size() && (y.ff-u.rbegin()->ff)/v.ff <= u.rbegin()->ss) u.rbegin()->ss = (y.ff-u.rbegin()->ff)/v.ff+k-1;
else u.push_back(y);
}
swap(arr[i], u);
u.clear();
}
//cout<<endl;
// for(int i = 0; i < w.size(); i++) {
// cout<<w[i].ff<<endl;
// for(pi x : arr[i]) cout<<x.ff<<bl<<x.ss<<bl;
// cout<<endl;
// }
// arr[0] = {pi(0, 2)};
// arr[1] = {pi(1, 1), pi(2, 1)};
// arr[2] = {pi(1, 2), pi(2, 1)};
// arr[3] = {pi(2, 2), pi(3, 1)};
// arr[4] = {pi(4, 1)};
ll cnt = 0;
for(int i = 0; i < w.size(); i++) {
int it1 = lower_bound(all(w), pll(w[i].ff+v.ff, w[i].ss))-w.begin();
if(w[it1] != pll(w[i].ff+v.ff, w[i].ss)) continue;
int it2 = lower_bound(all(w), pll(w[i].ff-v.ss, (w[i].ss+1)%v.ff))-w.begin();
if(w[it2] != pll(w[i].ff-v.ss, (w[i].ss+1)%v.ff)) continue;
int it3 = lower_bound(all(w), pll(w[i].ff+v.ff-v.ss, (w[i].ss+1)%v.ff))-w.begin();
if(w[it3] != pll(w[i].ff+v.ff-v.ss, (w[i].ss+1)%v.ff)) continue;
for(auto y : arr[i]) ww.push_back(y.ff);
for(auto y : arr[it1]) ww.push_back(y.ff);
for(auto y : arr[it2]) ww.push_back(y.ff);
for(auto y : arr[it3]) ww.push_back(y.ff);
sort(all(ww)); comp(ww);
ll p = -MOD;
for(int y : ww) {
int a = lower_bound(all(arr[i]), pi(y+1, 0)) - arr[i].begin() - 1;
int b = lower_bound(all(arr[it1]), pi(y+1, 0)) - arr[it1].begin() - 1;
int c = lower_bound(all(arr[it2]), pi(y+2, 0)) - arr[it2].begin() - 1;
int d = lower_bound(all(arr[it3]), pi(y+2, 0)) - arr[it3].begin() - 1;
if(a == -1 || b == -1 || c == -1 || d == -1) continue;
ll l = max(max(arr[i][a].ff, arr[it1][b].ff), max(arr[it2][c].ff, arr[it3][d].ff)-1);
ll r = min(min(arr[i][a].ff+v.ff*arr[i][a].ss, arr[it1][b].ff+v.ff*arr[it1][b].ss), min(arr[it2][c].ff+v.ff*arr[it2][c].ss, arr[it3][d].ff+v.ff*arr[it3][d].ss)-1);
//if(w[i] == -1) cout << l<<bl<<r<<endl;
if(p >= l) l = p + v.ff;
if(l > r) continue;
cnt += (r-l)/v.ff+1;
p = r;
}
//cout << w[i].ff<<bl<<cnt<<endl;
}
cout << cnt;
}
Compilation message
2016_ho_t4.cpp: In function 'int main()':
2016_ho_t4.cpp:68:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
68 | for(int i = 0; i < w.size(); i++) {
| ~~^~~~~~~~~~
2016_ho_t4.cpp:95:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
95 | for(int i = 0; i < w.size(); i++) {
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2652 KB |
Output is correct |
2 |
Correct |
1 ms |
2652 KB |
Output is correct |
3 |
Correct |
1 ms |
2652 KB |
Output is correct |
4 |
Correct |
1 ms |
2652 KB |
Output is correct |
5 |
Correct |
1 ms |
2652 KB |
Output is correct |
6 |
Correct |
1 ms |
2652 KB |
Output is correct |
7 |
Correct |
1 ms |
2904 KB |
Output is correct |
8 |
Correct |
1 ms |
2652 KB |
Output is correct |
9 |
Correct |
1 ms |
2652 KB |
Output is correct |
10 |
Correct |
1 ms |
2648 KB |
Output is correct |
11 |
Correct |
1 ms |
2652 KB |
Output is correct |
12 |
Correct |
1 ms |
2652 KB |
Output is correct |
13 |
Correct |
1 ms |
2652 KB |
Output is correct |
14 |
Correct |
1 ms |
2652 KB |
Output is correct |
15 |
Correct |
1 ms |
2652 KB |
Output is correct |
16 |
Correct |
1 ms |
2652 KB |
Output is correct |
17 |
Correct |
1 ms |
2652 KB |
Output is correct |
18 |
Correct |
1 ms |
2652 KB |
Output is correct |
19 |
Correct |
1 ms |
2652 KB |
Output is correct |
20 |
Correct |
1 ms |
2648 KB |
Output is correct |
21 |
Correct |
1 ms |
2648 KB |
Output is correct |
22 |
Correct |
1 ms |
2652 KB |
Output is correct |
23 |
Correct |
1 ms |
2652 KB |
Output is correct |
24 |
Correct |
1 ms |
2652 KB |
Output is correct |
25 |
Correct |
1 ms |
2652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2652 KB |
Output is correct |
2 |
Correct |
1 ms |
2652 KB |
Output is correct |
3 |
Correct |
1 ms |
2652 KB |
Output is correct |
4 |
Correct |
1 ms |
2652 KB |
Output is correct |
5 |
Correct |
1 ms |
2652 KB |
Output is correct |
6 |
Correct |
1 ms |
2652 KB |
Output is correct |
7 |
Correct |
1 ms |
2904 KB |
Output is correct |
8 |
Correct |
1 ms |
2652 KB |
Output is correct |
9 |
Correct |
1 ms |
2652 KB |
Output is correct |
10 |
Correct |
1 ms |
2648 KB |
Output is correct |
11 |
Correct |
1 ms |
2652 KB |
Output is correct |
12 |
Correct |
1 ms |
2652 KB |
Output is correct |
13 |
Correct |
1 ms |
2652 KB |
Output is correct |
14 |
Correct |
1 ms |
2652 KB |
Output is correct |
15 |
Correct |
1 ms |
2652 KB |
Output is correct |
16 |
Correct |
1 ms |
2652 KB |
Output is correct |
17 |
Correct |
1 ms |
2652 KB |
Output is correct |
18 |
Correct |
1 ms |
2652 KB |
Output is correct |
19 |
Correct |
1 ms |
2652 KB |
Output is correct |
20 |
Correct |
1 ms |
2648 KB |
Output is correct |
21 |
Correct |
1 ms |
2648 KB |
Output is correct |
22 |
Correct |
1 ms |
2652 KB |
Output is correct |
23 |
Correct |
1 ms |
2652 KB |
Output is correct |
24 |
Correct |
1 ms |
2652 KB |
Output is correct |
25 |
Correct |
1 ms |
2652 KB |
Output is correct |
26 |
Correct |
1 ms |
2652 KB |
Output is correct |
27 |
Correct |
2 ms |
2652 KB |
Output is correct |
28 |
Correct |
3 ms |
2908 KB |
Output is correct |
29 |
Correct |
7 ms |
3492 KB |
Output is correct |
30 |
Correct |
9 ms |
3420 KB |
Output is correct |
31 |
Correct |
20 ms |
6736 KB |
Output is correct |
32 |
Correct |
14 ms |
3672 KB |
Output is correct |
33 |
Correct |
15 ms |
3932 KB |
Output is correct |
34 |
Correct |
13 ms |
4188 KB |
Output is correct |
35 |
Correct |
13 ms |
3932 KB |
Output is correct |
36 |
Correct |
12 ms |
3676 KB |
Output is correct |
37 |
Correct |
13 ms |
4008 KB |
Output is correct |
38 |
Correct |
13 ms |
3932 KB |
Output is correct |
39 |
Correct |
13 ms |
4084 KB |
Output is correct |
40 |
Correct |
12 ms |
3676 KB |
Output is correct |
41 |
Correct |
12 ms |
3676 KB |
Output is correct |
42 |
Correct |
11 ms |
3544 KB |
Output is correct |
43 |
Correct |
14 ms |
3932 KB |
Output is correct |
44 |
Correct |
13 ms |
3932 KB |
Output is correct |
45 |
Correct |
11 ms |
3676 KB |
Output is correct |
46 |
Correct |
15 ms |
5208 KB |
Output is correct |
47 |
Correct |
17 ms |
5212 KB |
Output is correct |
48 |
Correct |
26 ms |
7516 KB |
Output is correct |
49 |
Correct |
17 ms |
7516 KB |
Output is correct |
50 |
Correct |
22 ms |
7516 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2652 KB |
Output is correct |
2 |
Correct |
1 ms |
2652 KB |
Output is correct |
3 |
Correct |
1 ms |
2652 KB |
Output is correct |
4 |
Correct |
1 ms |
2652 KB |
Output is correct |
5 |
Correct |
1 ms |
2652 KB |
Output is correct |
6 |
Correct |
1 ms |
2652 KB |
Output is correct |
7 |
Correct |
1 ms |
2904 KB |
Output is correct |
8 |
Correct |
1 ms |
2652 KB |
Output is correct |
9 |
Correct |
1 ms |
2652 KB |
Output is correct |
10 |
Correct |
1 ms |
2648 KB |
Output is correct |
11 |
Correct |
1 ms |
2652 KB |
Output is correct |
12 |
Correct |
1 ms |
2652 KB |
Output is correct |
13 |
Correct |
1 ms |
2652 KB |
Output is correct |
14 |
Correct |
1 ms |
2652 KB |
Output is correct |
15 |
Correct |
1 ms |
2652 KB |
Output is correct |
16 |
Correct |
1 ms |
2652 KB |
Output is correct |
17 |
Correct |
1 ms |
2652 KB |
Output is correct |
18 |
Correct |
1 ms |
2652 KB |
Output is correct |
19 |
Correct |
1 ms |
2652 KB |
Output is correct |
20 |
Correct |
1 ms |
2648 KB |
Output is correct |
21 |
Correct |
1 ms |
2648 KB |
Output is correct |
22 |
Correct |
1 ms |
2652 KB |
Output is correct |
23 |
Correct |
1 ms |
2652 KB |
Output is correct |
24 |
Correct |
1 ms |
2652 KB |
Output is correct |
25 |
Correct |
1 ms |
2652 KB |
Output is correct |
26 |
Correct |
1 ms |
2648 KB |
Output is correct |
27 |
Correct |
1 ms |
2652 KB |
Output is correct |
28 |
Correct |
1 ms |
2652 KB |
Output is correct |
29 |
Correct |
1 ms |
2652 KB |
Output is correct |
30 |
Correct |
1 ms |
2652 KB |
Output is correct |
31 |
Correct |
1 ms |
2652 KB |
Output is correct |
32 |
Correct |
1 ms |
2652 KB |
Output is correct |
33 |
Correct |
1 ms |
2652 KB |
Output is correct |
34 |
Correct |
1 ms |
2812 KB |
Output is correct |
35 |
Correct |
1 ms |
2652 KB |
Output is correct |
36 |
Correct |
1 ms |
2652 KB |
Output is correct |
37 |
Correct |
1 ms |
2652 KB |
Output is correct |
38 |
Correct |
1 ms |
2652 KB |
Output is correct |
39 |
Correct |
1 ms |
2652 KB |
Output is correct |
40 |
Correct |
1 ms |
2652 KB |
Output is correct |
41 |
Correct |
1 ms |
2652 KB |
Output is correct |
42 |
Correct |
1 ms |
2652 KB |
Output is correct |
43 |
Correct |
1 ms |
2652 KB |
Output is correct |
44 |
Correct |
1 ms |
2648 KB |
Output is correct |
45 |
Correct |
1 ms |
2820 KB |
Output is correct |
46 |
Correct |
1 ms |
2652 KB |
Output is correct |
47 |
Correct |
1 ms |
2808 KB |
Output is correct |
48 |
Correct |
1 ms |
2652 KB |
Output is correct |
49 |
Correct |
1 ms |
2652 KB |
Output is correct |
50 |
Correct |
1 ms |
2652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2652 KB |
Output is correct |
2 |
Correct |
1 ms |
2652 KB |
Output is correct |
3 |
Correct |
1 ms |
2652 KB |
Output is correct |
4 |
Correct |
1 ms |
2652 KB |
Output is correct |
5 |
Correct |
1 ms |
2652 KB |
Output is correct |
6 |
Correct |
1 ms |
2652 KB |
Output is correct |
7 |
Correct |
1 ms |
2904 KB |
Output is correct |
8 |
Correct |
1 ms |
2652 KB |
Output is correct |
9 |
Correct |
1 ms |
2652 KB |
Output is correct |
10 |
Correct |
1 ms |
2648 KB |
Output is correct |
11 |
Correct |
1 ms |
2652 KB |
Output is correct |
12 |
Correct |
1 ms |
2652 KB |
Output is correct |
13 |
Correct |
1 ms |
2652 KB |
Output is correct |
14 |
Correct |
1 ms |
2652 KB |
Output is correct |
15 |
Correct |
1 ms |
2652 KB |
Output is correct |
16 |
Correct |
1 ms |
2652 KB |
Output is correct |
17 |
Correct |
1 ms |
2652 KB |
Output is correct |
18 |
Correct |
1 ms |
2652 KB |
Output is correct |
19 |
Correct |
1 ms |
2652 KB |
Output is correct |
20 |
Correct |
1 ms |
2648 KB |
Output is correct |
21 |
Correct |
1 ms |
2648 KB |
Output is correct |
22 |
Correct |
1 ms |
2652 KB |
Output is correct |
23 |
Correct |
1 ms |
2652 KB |
Output is correct |
24 |
Correct |
1 ms |
2652 KB |
Output is correct |
25 |
Correct |
1 ms |
2652 KB |
Output is correct |
26 |
Correct |
1 ms |
2652 KB |
Output is correct |
27 |
Correct |
2 ms |
2652 KB |
Output is correct |
28 |
Correct |
3 ms |
2908 KB |
Output is correct |
29 |
Correct |
7 ms |
3492 KB |
Output is correct |
30 |
Correct |
9 ms |
3420 KB |
Output is correct |
31 |
Correct |
20 ms |
6736 KB |
Output is correct |
32 |
Correct |
14 ms |
3672 KB |
Output is correct |
33 |
Correct |
15 ms |
3932 KB |
Output is correct |
34 |
Correct |
13 ms |
4188 KB |
Output is correct |
35 |
Correct |
13 ms |
3932 KB |
Output is correct |
36 |
Correct |
12 ms |
3676 KB |
Output is correct |
37 |
Correct |
13 ms |
4008 KB |
Output is correct |
38 |
Correct |
13 ms |
3932 KB |
Output is correct |
39 |
Correct |
13 ms |
4084 KB |
Output is correct |
40 |
Correct |
12 ms |
3676 KB |
Output is correct |
41 |
Correct |
12 ms |
3676 KB |
Output is correct |
42 |
Correct |
11 ms |
3544 KB |
Output is correct |
43 |
Correct |
14 ms |
3932 KB |
Output is correct |
44 |
Correct |
13 ms |
3932 KB |
Output is correct |
45 |
Correct |
11 ms |
3676 KB |
Output is correct |
46 |
Correct |
15 ms |
5208 KB |
Output is correct |
47 |
Correct |
17 ms |
5212 KB |
Output is correct |
48 |
Correct |
26 ms |
7516 KB |
Output is correct |
49 |
Correct |
17 ms |
7516 KB |
Output is correct |
50 |
Correct |
22 ms |
7516 KB |
Output is correct |
51 |
Correct |
1 ms |
2648 KB |
Output is correct |
52 |
Correct |
1 ms |
2652 KB |
Output is correct |
53 |
Correct |
1 ms |
2652 KB |
Output is correct |
54 |
Correct |
1 ms |
2652 KB |
Output is correct |
55 |
Correct |
1 ms |
2652 KB |
Output is correct |
56 |
Correct |
1 ms |
2652 KB |
Output is correct |
57 |
Correct |
1 ms |
2652 KB |
Output is correct |
58 |
Correct |
1 ms |
2652 KB |
Output is correct |
59 |
Correct |
1 ms |
2812 KB |
Output is correct |
60 |
Correct |
1 ms |
2652 KB |
Output is correct |
61 |
Correct |
1 ms |
2652 KB |
Output is correct |
62 |
Correct |
1 ms |
2652 KB |
Output is correct |
63 |
Correct |
1 ms |
2652 KB |
Output is correct |
64 |
Correct |
1 ms |
2652 KB |
Output is correct |
65 |
Correct |
1 ms |
2652 KB |
Output is correct |
66 |
Correct |
1 ms |
2652 KB |
Output is correct |
67 |
Correct |
1 ms |
2652 KB |
Output is correct |
68 |
Correct |
1 ms |
2652 KB |
Output is correct |
69 |
Correct |
1 ms |
2648 KB |
Output is correct |
70 |
Correct |
1 ms |
2820 KB |
Output is correct |
71 |
Correct |
1 ms |
2652 KB |
Output is correct |
72 |
Correct |
1 ms |
2808 KB |
Output is correct |
73 |
Correct |
1 ms |
2652 KB |
Output is correct |
74 |
Correct |
1 ms |
2652 KB |
Output is correct |
75 |
Correct |
1 ms |
2652 KB |
Output is correct |
76 |
Correct |
2 ms |
2908 KB |
Output is correct |
77 |
Correct |
2 ms |
2908 KB |
Output is correct |
78 |
Correct |
12 ms |
4956 KB |
Output is correct |
79 |
Correct |
22 ms |
7352 KB |
Output is correct |
80 |
Correct |
58 ms |
4312 KB |
Output is correct |
81 |
Correct |
13 ms |
4440 KB |
Output is correct |
82 |
Correct |
200 ms |
4820 KB |
Output is correct |
83 |
Correct |
25 ms |
4444 KB |
Output is correct |
84 |
Correct |
163 ms |
5080 KB |
Output is correct |
85 |
Correct |
100 ms |
5212 KB |
Output is correct |
86 |
Correct |
44 ms |
12368 KB |
Output is correct |
87 |
Correct |
251 ms |
5468 KB |
Output is correct |
88 |
Correct |
111 ms |
5212 KB |
Output is correct |
89 |
Correct |
84 ms |
5276 KB |
Output is correct |
90 |
Correct |
13 ms |
3928 KB |
Output is correct |
91 |
Correct |
165 ms |
5468 KB |
Output is correct |
92 |
Correct |
142 ms |
5720 KB |
Output is correct |
93 |
Correct |
74 ms |
5320 KB |
Output is correct |
94 |
Correct |
67 ms |
4700 KB |
Output is correct |
95 |
Correct |
83 ms |
4572 KB |
Output is correct |
96 |
Execution timed out |
1101 ms |
7104 KB |
Time limit exceeded |
97 |
Halted |
0 ms |
0 KB |
- |