# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
51680 |
2018-06-19T23:26:02 Z |
gs13105 |
None (JOI16_ho_t4) |
C++17 |
|
99 ms |
9796 KB |
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <iterator>
using namespace std;
struct pos
{
int x, y;
bool operator <(const pos &p) const
{
return x != p.x ? x < p.x : y < p.y;
}
bool operator ==(const pos &p) const
{
return x == p.x && y == p.y;
}
};
struct eve
{
int x, e;
bool operator <(const eve &a) const
{
return x != a.x ? x < a.x : e < a.e;
}
};
inline int irem(int x, int y)
{
assert(y != 0);
y = abs(y);
return (x % y + y) % y;
}
int kx, ky;
pair<pos, int> decom(pos p)
{
if(kx != 0)
{
pos q;
q.x = irem(p.x, kx);
int t = (q.x - p.x) / kx;
q.y = p.y + t * ky;
return { q, t };
}
if(ky != 0)
{
pos q;
q.y = irem(p.y, ky);
int t = (q.y - p.y) / ky;
q.x = p.x + t * kx;
return { q, t };
}
return { p, 0 };
}
vector<pos> com;
inline int idx(pos p)
{
return lower_bound(com.begin(), com.end(), p) - com.begin();
}
char str[100010];
pos arr[100010];
pos base[100010];
int off[100010];
vector<int> lis[100010];
const int dx[4] = { 0, 0, 1, 1 };
const int dy[4] = { 0, 1, 0, 1 };
int main()
{
//freopen("in", "r", stdin);
//freopen("out", "w", stdout);
int n, k, i;
scanf("%d%d%s", &n, &k, str);
kx = ky = 0;
for(i = 0; i <= n; i++)
{
arr[i] = { kx, ky };
if(i == n)
break;
if(str[i] == 'E')
kx++;
else if(str[i] == 'N')
ky++;
else if(str[i] == 'W')
kx--;
else
ky--;
}
for(i = 0; i <= n; i++)
{
tie(base[i], off[i]) = decom(arr[i]);
com.push_back(base[i]);
}
sort(com.begin(), com.end());
com.erase(unique(com.begin(), com.end()), com.end());
int sz = com.size();
for(i = 0; i <= n; i++)
lis[idx(base[i])].push_back(off[i]);
for(i = 0; i < sz; i++)
sort(lis[i].begin(), lis[i].end());
long long res = 0;
for(i = 0; i < sz; i++)
{
int a[4];
int b[4];
bool ok = 1;
for(int d = 0; d < 4; d++)
{
pos p;
tie(p, b[d]) = decom({ com[i].x + dx[d], com[i].y + dy[d] });
a[d] = idx(p);
if(!(a[d] < com.size() && com[a[d]] == p))
{
ok = 0;
break;
}
}
if(!ok)
continue;
vector<eve> v;
for(int d = 0; d < 4; d++)
{
for(int l : lis[a[d]])
{
v.push_back({ l - b[d], d + 1 });
v.push_back({ l - b[d] + k, -(d + 1) });
}
}
sort(v.begin(), v.end());
int s[4];
memset(s, 0, sizeof s);
int cnt = 0;
bool inr = 0;
int sta;
for(int j = 0; j < v.size(); j++)
{
eve t = v[j];
if(t.e > 0)
{
t.e--;
s[t.e]++;
if(s[t.e] == 1)
cnt++;
}
else
{
t.e = -t.e - 1;
s[t.e]--;
if(s[t.e] == 0)
cnt--;
}
if(j == (int)v.size() - 1 || t.x != v[j + 1].x)
{
if(!inr && cnt == 4)
{
inr = 1;
sta = t.x;
}
else if(inr && cnt != 4)
{
inr = 0;
res += t.x - sta;
}
}
}
}
printf("%lld\n", res);
return 0;
}
Compilation message
2016_ho_t4.cpp: In function 'int main()':
2016_ho_t4.cpp:141:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(!(a[d] < com.size() && com[a[d]] == p))
~~~~~^~~~~~~~~~~~
2016_ho_t4.cpp:167:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j = 0; j < v.size(); j++)
~~^~~~~~~~~~
2016_ho_t4.cpp:95:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%s", &n, &k, str);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~
2016_ho_t4.cpp:195:32: warning: 'sta' may be used uninitialized in this function [-Wmaybe-uninitialized]
res += t.x - sta;
~~~~^~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
2680 KB |
Output is correct |
2 |
Correct |
5 ms |
2680 KB |
Output is correct |
3 |
Correct |
5 ms |
2864 KB |
Output is correct |
4 |
Correct |
5 ms |
2864 KB |
Output is correct |
5 |
Correct |
4 ms |
2888 KB |
Output is correct |
6 |
Correct |
5 ms |
2888 KB |
Output is correct |
7 |
Correct |
4 ms |
2888 KB |
Output is correct |
8 |
Correct |
4 ms |
2904 KB |
Output is correct |
9 |
Correct |
4 ms |
2940 KB |
Output is correct |
10 |
Correct |
4 ms |
3020 KB |
Output is correct |
11 |
Correct |
4 ms |
3020 KB |
Output is correct |
12 |
Correct |
5 ms |
3068 KB |
Output is correct |
13 |
Correct |
4 ms |
3068 KB |
Output is correct |
14 |
Correct |
4 ms |
3068 KB |
Output is correct |
15 |
Correct |
4 ms |
3068 KB |
Output is correct |
16 |
Correct |
5 ms |
3068 KB |
Output is correct |
17 |
Correct |
4 ms |
3068 KB |
Output is correct |
18 |
Correct |
4 ms |
3068 KB |
Output is correct |
19 |
Correct |
4 ms |
3068 KB |
Output is correct |
20 |
Correct |
4 ms |
3068 KB |
Output is correct |
21 |
Correct |
5 ms |
3068 KB |
Output is correct |
22 |
Correct |
4 ms |
3068 KB |
Output is correct |
23 |
Correct |
4 ms |
3068 KB |
Output is correct |
24 |
Correct |
5 ms |
3068 KB |
Output is correct |
25 |
Correct |
5 ms |
3068 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
2680 KB |
Output is correct |
2 |
Correct |
5 ms |
2680 KB |
Output is correct |
3 |
Correct |
5 ms |
2864 KB |
Output is correct |
4 |
Correct |
5 ms |
2864 KB |
Output is correct |
5 |
Correct |
4 ms |
2888 KB |
Output is correct |
6 |
Correct |
5 ms |
2888 KB |
Output is correct |
7 |
Correct |
4 ms |
2888 KB |
Output is correct |
8 |
Correct |
4 ms |
2904 KB |
Output is correct |
9 |
Correct |
4 ms |
2940 KB |
Output is correct |
10 |
Correct |
4 ms |
3020 KB |
Output is correct |
11 |
Correct |
4 ms |
3020 KB |
Output is correct |
12 |
Correct |
5 ms |
3068 KB |
Output is correct |
13 |
Correct |
4 ms |
3068 KB |
Output is correct |
14 |
Correct |
4 ms |
3068 KB |
Output is correct |
15 |
Correct |
4 ms |
3068 KB |
Output is correct |
16 |
Correct |
5 ms |
3068 KB |
Output is correct |
17 |
Correct |
4 ms |
3068 KB |
Output is correct |
18 |
Correct |
4 ms |
3068 KB |
Output is correct |
19 |
Correct |
4 ms |
3068 KB |
Output is correct |
20 |
Correct |
4 ms |
3068 KB |
Output is correct |
21 |
Correct |
5 ms |
3068 KB |
Output is correct |
22 |
Correct |
4 ms |
3068 KB |
Output is correct |
23 |
Correct |
4 ms |
3068 KB |
Output is correct |
24 |
Correct |
5 ms |
3068 KB |
Output is correct |
25 |
Correct |
5 ms |
3068 KB |
Output is correct |
26 |
Correct |
4 ms |
3068 KB |
Output is correct |
27 |
Correct |
10 ms |
3196 KB |
Output is correct |
28 |
Correct |
15 ms |
3580 KB |
Output is correct |
29 |
Correct |
53 ms |
4852 KB |
Output is correct |
30 |
Correct |
55 ms |
5488 KB |
Output is correct |
31 |
Correct |
70 ms |
8352 KB |
Output is correct |
32 |
Correct |
72 ms |
8352 KB |
Output is correct |
33 |
Correct |
72 ms |
8352 KB |
Output is correct |
34 |
Correct |
82 ms |
8352 KB |
Output is correct |
35 |
Correct |
81 ms |
8352 KB |
Output is correct |
36 |
Correct |
99 ms |
8352 KB |
Output is correct |
37 |
Correct |
77 ms |
8352 KB |
Output is correct |
38 |
Correct |
85 ms |
8352 KB |
Output is correct |
39 |
Correct |
70 ms |
8352 KB |
Output is correct |
40 |
Correct |
73 ms |
8352 KB |
Output is correct |
41 |
Correct |
80 ms |
8352 KB |
Output is correct |
42 |
Correct |
84 ms |
8352 KB |
Output is correct |
43 |
Correct |
84 ms |
8352 KB |
Output is correct |
44 |
Correct |
89 ms |
8352 KB |
Output is correct |
45 |
Correct |
76 ms |
8352 KB |
Output is correct |
46 |
Correct |
65 ms |
8352 KB |
Output is correct |
47 |
Correct |
79 ms |
8352 KB |
Output is correct |
48 |
Correct |
83 ms |
9796 KB |
Output is correct |
49 |
Correct |
57 ms |
9796 KB |
Output is correct |
50 |
Correct |
72 ms |
9796 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
2680 KB |
Output is correct |
2 |
Correct |
5 ms |
2680 KB |
Output is correct |
3 |
Correct |
5 ms |
2864 KB |
Output is correct |
4 |
Correct |
5 ms |
2864 KB |
Output is correct |
5 |
Correct |
4 ms |
2888 KB |
Output is correct |
6 |
Correct |
5 ms |
2888 KB |
Output is correct |
7 |
Correct |
4 ms |
2888 KB |
Output is correct |
8 |
Correct |
4 ms |
2904 KB |
Output is correct |
9 |
Correct |
4 ms |
2940 KB |
Output is correct |
10 |
Correct |
4 ms |
3020 KB |
Output is correct |
11 |
Correct |
4 ms |
3020 KB |
Output is correct |
12 |
Correct |
5 ms |
3068 KB |
Output is correct |
13 |
Correct |
4 ms |
3068 KB |
Output is correct |
14 |
Correct |
4 ms |
3068 KB |
Output is correct |
15 |
Correct |
4 ms |
3068 KB |
Output is correct |
16 |
Correct |
5 ms |
3068 KB |
Output is correct |
17 |
Correct |
4 ms |
3068 KB |
Output is correct |
18 |
Correct |
4 ms |
3068 KB |
Output is correct |
19 |
Correct |
4 ms |
3068 KB |
Output is correct |
20 |
Correct |
4 ms |
3068 KB |
Output is correct |
21 |
Correct |
5 ms |
3068 KB |
Output is correct |
22 |
Correct |
4 ms |
3068 KB |
Output is correct |
23 |
Correct |
4 ms |
3068 KB |
Output is correct |
24 |
Correct |
5 ms |
3068 KB |
Output is correct |
25 |
Correct |
5 ms |
3068 KB |
Output is correct |
26 |
Correct |
4 ms |
9796 KB |
Output is correct |
27 |
Incorrect |
4 ms |
9796 KB |
Output isn't correct |
28 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
2680 KB |
Output is correct |
2 |
Correct |
5 ms |
2680 KB |
Output is correct |
3 |
Correct |
5 ms |
2864 KB |
Output is correct |
4 |
Correct |
5 ms |
2864 KB |
Output is correct |
5 |
Correct |
4 ms |
2888 KB |
Output is correct |
6 |
Correct |
5 ms |
2888 KB |
Output is correct |
7 |
Correct |
4 ms |
2888 KB |
Output is correct |
8 |
Correct |
4 ms |
2904 KB |
Output is correct |
9 |
Correct |
4 ms |
2940 KB |
Output is correct |
10 |
Correct |
4 ms |
3020 KB |
Output is correct |
11 |
Correct |
4 ms |
3020 KB |
Output is correct |
12 |
Correct |
5 ms |
3068 KB |
Output is correct |
13 |
Correct |
4 ms |
3068 KB |
Output is correct |
14 |
Correct |
4 ms |
3068 KB |
Output is correct |
15 |
Correct |
4 ms |
3068 KB |
Output is correct |
16 |
Correct |
5 ms |
3068 KB |
Output is correct |
17 |
Correct |
4 ms |
3068 KB |
Output is correct |
18 |
Correct |
4 ms |
3068 KB |
Output is correct |
19 |
Correct |
4 ms |
3068 KB |
Output is correct |
20 |
Correct |
4 ms |
3068 KB |
Output is correct |
21 |
Correct |
5 ms |
3068 KB |
Output is correct |
22 |
Correct |
4 ms |
3068 KB |
Output is correct |
23 |
Correct |
4 ms |
3068 KB |
Output is correct |
24 |
Correct |
5 ms |
3068 KB |
Output is correct |
25 |
Correct |
5 ms |
3068 KB |
Output is correct |
26 |
Correct |
4 ms |
3068 KB |
Output is correct |
27 |
Correct |
10 ms |
3196 KB |
Output is correct |
28 |
Correct |
15 ms |
3580 KB |
Output is correct |
29 |
Correct |
53 ms |
4852 KB |
Output is correct |
30 |
Correct |
55 ms |
5488 KB |
Output is correct |
31 |
Correct |
70 ms |
8352 KB |
Output is correct |
32 |
Correct |
72 ms |
8352 KB |
Output is correct |
33 |
Correct |
72 ms |
8352 KB |
Output is correct |
34 |
Correct |
82 ms |
8352 KB |
Output is correct |
35 |
Correct |
81 ms |
8352 KB |
Output is correct |
36 |
Correct |
99 ms |
8352 KB |
Output is correct |
37 |
Correct |
77 ms |
8352 KB |
Output is correct |
38 |
Correct |
85 ms |
8352 KB |
Output is correct |
39 |
Correct |
70 ms |
8352 KB |
Output is correct |
40 |
Correct |
73 ms |
8352 KB |
Output is correct |
41 |
Correct |
80 ms |
8352 KB |
Output is correct |
42 |
Correct |
84 ms |
8352 KB |
Output is correct |
43 |
Correct |
84 ms |
8352 KB |
Output is correct |
44 |
Correct |
89 ms |
8352 KB |
Output is correct |
45 |
Correct |
76 ms |
8352 KB |
Output is correct |
46 |
Correct |
65 ms |
8352 KB |
Output is correct |
47 |
Correct |
79 ms |
8352 KB |
Output is correct |
48 |
Correct |
83 ms |
9796 KB |
Output is correct |
49 |
Correct |
57 ms |
9796 KB |
Output is correct |
50 |
Correct |
72 ms |
9796 KB |
Output is correct |
51 |
Correct |
4 ms |
9796 KB |
Output is correct |
52 |
Incorrect |
4 ms |
9796 KB |
Output isn't correct |
53 |
Halted |
0 ms |
0 KB |
- |