# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
128715 |
2019-07-11T08:37:17 Z |
이온조(#3159) |
None (JOI16_ho_t4) |
C++14 |
|
341 ms |
34576 KB |
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
using pli = pair<long long, int>;
using tiii = tuple<int, int, int>;
#define X first
#define Y second
const int le9 = 1e9;
const pii INF = {-1e9, -1e9};
pii df; int dx, dy;
int N, K, P[1000009];
int x1[4][100009], x2[4][100009], y[100009];
char S[100009];
set<pii> st;
void mv(pii &CR, char c) {
if(c == 'S') --CR.Y;
if(c == 'N') ++CR.Y;
if(c == 'W') --CR.X;
if(c == 'E') ++CR.X;
}
void input() {
scanf("%d%d",&N,&K);
for(int i=1; i<=N; i++) {
scanf(" %c", &S[i]);
mv(df, S[i]);
}
if(df.X < 0) {
df.X = -df.X;
for(int i=1; i<=N; i++) {
if(S[i] == 'W') S[i] = 'E';
else if(S[i] == 'E') S[i] = 'W';
}
}
if(df.Y < 0) {
df.Y = -df.Y;
for(int i=1; i<=N; i++) {
if(S[i] == 'N') S[i] = 'S';
else if(S[i] == 'S') S[i] = 'N';
}
}
}
void go(pii &now) {
st.insert(now);
for(int i=1; i<=N; i++) {
mv(now, S[i]);
st.insert(now);
}
}
int cnt() {
int ret = 0;
for(auto& it: st) {
int c = 0;
if(st.find({it.X+1, it.Y}) != st.end()) ++c;
if(st.find({it.X, it.Y+1}) != st.end()) ++c;
if(st.find({it.X+1, it.Y+1}) != st.end()) ++c;
if(c == 3) ++ret;
}
return ret;
}
pli geti(pii A) {
if(dx == 0) return {A.X, A.Y % dy};
if(dy == 0) return {A.Y, A.X % dx};
return {1LL * A.X * dy - 1LL * A.Y * dx, A.Y % dy};
}
int day(pii A, pii B) {
return (dx ? (A.X - B.X) / dx : (A.Y - B.Y) / dy) + 1;
}
vector<pii> A;
pii RC(pii U) {
if(U.Y == 0) return A[U.X];
if(U.Y == 1) return {A[U.X].X+1, A[U.X].Y};
if(U.Y == 2) return {A[U.X].X, A[U.X].Y+1};
if(U.Y == 3) return {A[U.X].X+1, A[U.X].Y+1};
}
vector<pii> T[400009];
int main() {
input(); tie(dx, dy) = df;
pii now = {le9, le9}; go(now);
// printf("dx: %d, dy: %d\n", dx, dy);
if(dx == 0 && dy == 0) return !printf("%d", cnt());
map<pli, int> id; int M = 0;
for(auto& it: st) {
if(id[geti(it)] == 0) id[geti(it)] = ++M;
if(id[geti({it.X+1, it.Y})] == 0) id[geti({it.X+1, it.Y})] = ++M;
if(id[geti({it.X, it.Y+1})] == 0) id[geti({it.X, it.Y+1})] = ++M;
if(id[geti({it.X+1, it.Y+1})] == 0) id[geti({it.X+1, it.Y+1})] = ++M;
}
for(auto& it: st) {
T[id[geti(it)]].push_back({A.size(), 0});
T[id[geti({it.X+1, it.Y})]].push_back({A.size(), 1});
T[id[geti({it.X, it.Y+1})]].push_back({A.size(), 2});
T[id[geti({it.X+1, it.Y+1})]].push_back({A.size(), 3});
A.push_back(it);
}
int E = A.size();
for(int i=1; i<=M; i++) {
sort(T[i].begin(), T[i].end(), [&](pii PP, pii QQ) {
if(RC(PP) == RC(QQ)) return PP.Y < QQ.Y;
return RC(PP) < RC(QQ);
});
// for(auto& it: T[i]) printf("Ai: %d, (%d, %d), type: %d\n", it.X, RC(it).X - le9, RC(it).Y - le9, it.Y);
// puts("------------------");
// calculate x1
pii prv = INF;
for(auto& it: T[i]) {
if(it.Y == 0) prv = RC(it);
else {
if(prv == INF) continue;
x1[it.Y][it.X] = day(RC(it), prv);
}
}
reverse(T[i].begin(), T[i].end());
// calculate x2 and y
prv = INF;
for(auto& it: T[i]) {
if(it.Y == 0) {
if(prv != INF) y[it.X] = day(prv, RC(it));
prv = RC(it);
}
else {
if(prv == INF) continue;
x2[it.Y][it.X] = day(prv, RC(it));
}
}
}
int inf = 3*N+1;
for(int i=0; i<E; i++) {
int X1 = inf, X2 = inf, Y = inf;
if(x1[1][i] && x1[2][i] && x1[3][i]) X1 = max({x1[1][i], x1[2][i], x1[3][i]});
if(x2[1][i] && x2[2][i] && x2[3][i]) X2 = max({x2[1][i], x2[2][i], x2[3][i]});
if(y[i]) Y = y[i];
int s1 = X1, e1 = X1 + Y - 2;
int s2 = X2, e2 = Y - 1;
e1 = min(e1, X1 + X2 - 2);
s1 = min(s1, inf);
e1 = min(e1, inf);
s2 = min(s2, inf);
e2 = min(e2, inf);
if(s1 <= e1) ++P[s1], --P[e1+1];
if(s2 <= e2) ++P[s2], --P[e2+1];
// printf("i: %d, (%d, %d), x1: %d, x2: %d, y: %d, [%d, %d], [%d, %d]\n", i, A[i].X-le9, A[i].Y-le9, X1, X2, Y, s1, e1, s2, e2);
}
long long ds = 0, sum = 0;
for(int i=1; i<inf; i++) {
ds += P[i];
sum += ds;
if(i == K) return !printf("%lld", sum);
}
printf("%lld", sum + ds*(K-inf+1));
return 0;
}
Compilation message
2016_ho_t4.cpp: In function 'void input()':
2016_ho_t4.cpp:26: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:28:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf(" %c", &S[i]);
~~~~~^~~~~~~~~~~~~~
2016_ho_t4.cpp: In function 'pii RC(pii)':
2016_ho_t4.cpp:84:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
9720 KB |
Output is correct |
2 |
Correct |
10 ms |
9720 KB |
Output is correct |
3 |
Correct |
10 ms |
9720 KB |
Output is correct |
4 |
Correct |
10 ms |
9720 KB |
Output is correct |
5 |
Correct |
10 ms |
9720 KB |
Output is correct |
6 |
Correct |
10 ms |
9720 KB |
Output is correct |
7 |
Correct |
10 ms |
9720 KB |
Output is correct |
8 |
Correct |
10 ms |
9720 KB |
Output is correct |
9 |
Correct |
10 ms |
9720 KB |
Output is correct |
10 |
Correct |
10 ms |
9800 KB |
Output is correct |
11 |
Correct |
10 ms |
9760 KB |
Output is correct |
12 |
Correct |
10 ms |
9720 KB |
Output is correct |
13 |
Correct |
10 ms |
9724 KB |
Output is correct |
14 |
Correct |
10 ms |
9720 KB |
Output is correct |
15 |
Correct |
10 ms |
9720 KB |
Output is correct |
16 |
Correct |
10 ms |
9720 KB |
Output is correct |
17 |
Correct |
10 ms |
9720 KB |
Output is correct |
18 |
Correct |
10 ms |
9848 KB |
Output is correct |
19 |
Correct |
10 ms |
9720 KB |
Output is correct |
20 |
Correct |
10 ms |
9724 KB |
Output is correct |
21 |
Correct |
10 ms |
9720 KB |
Output is correct |
22 |
Correct |
10 ms |
9720 KB |
Output is correct |
23 |
Correct |
10 ms |
9720 KB |
Output is correct |
24 |
Correct |
10 ms |
9720 KB |
Output is correct |
25 |
Correct |
10 ms |
9720 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
9720 KB |
Output is correct |
2 |
Correct |
10 ms |
9720 KB |
Output is correct |
3 |
Correct |
10 ms |
9720 KB |
Output is correct |
4 |
Correct |
10 ms |
9720 KB |
Output is correct |
5 |
Correct |
10 ms |
9720 KB |
Output is correct |
6 |
Correct |
10 ms |
9720 KB |
Output is correct |
7 |
Correct |
10 ms |
9720 KB |
Output is correct |
8 |
Correct |
10 ms |
9720 KB |
Output is correct |
9 |
Correct |
10 ms |
9720 KB |
Output is correct |
10 |
Correct |
10 ms |
9800 KB |
Output is correct |
11 |
Correct |
10 ms |
9760 KB |
Output is correct |
12 |
Correct |
10 ms |
9720 KB |
Output is correct |
13 |
Correct |
10 ms |
9724 KB |
Output is correct |
14 |
Correct |
10 ms |
9720 KB |
Output is correct |
15 |
Correct |
10 ms |
9720 KB |
Output is correct |
16 |
Correct |
10 ms |
9720 KB |
Output is correct |
17 |
Correct |
10 ms |
9720 KB |
Output is correct |
18 |
Correct |
10 ms |
9848 KB |
Output is correct |
19 |
Correct |
10 ms |
9720 KB |
Output is correct |
20 |
Correct |
10 ms |
9724 KB |
Output is correct |
21 |
Correct |
10 ms |
9720 KB |
Output is correct |
22 |
Correct |
10 ms |
9720 KB |
Output is correct |
23 |
Correct |
10 ms |
9720 KB |
Output is correct |
24 |
Correct |
10 ms |
9720 KB |
Output is correct |
25 |
Correct |
10 ms |
9720 KB |
Output is correct |
26 |
Correct |
11 ms |
9848 KB |
Output is correct |
27 |
Correct |
14 ms |
9976 KB |
Output is correct |
28 |
Correct |
14 ms |
9976 KB |
Output is correct |
29 |
Correct |
48 ms |
12756 KB |
Output is correct |
30 |
Correct |
50 ms |
12664 KB |
Output is correct |
31 |
Correct |
249 ms |
30796 KB |
Output is correct |
32 |
Correct |
34 ms |
10744 KB |
Output is correct |
33 |
Correct |
78 ms |
14836 KB |
Output is correct |
34 |
Correct |
82 ms |
15476 KB |
Output is correct |
35 |
Correct |
77 ms |
14708 KB |
Output is correct |
36 |
Correct |
56 ms |
13616 KB |
Output is correct |
37 |
Correct |
36 ms |
10948 KB |
Output is correct |
38 |
Correct |
74 ms |
14196 KB |
Output is correct |
39 |
Correct |
67 ms |
14708 KB |
Output is correct |
40 |
Correct |
34 ms |
10744 KB |
Output is correct |
41 |
Correct |
57 ms |
12792 KB |
Output is correct |
42 |
Correct |
56 ms |
12792 KB |
Output is correct |
43 |
Correct |
77 ms |
14712 KB |
Output is correct |
44 |
Correct |
74 ms |
14356 KB |
Output is correct |
45 |
Correct |
63 ms |
13556 KB |
Output is correct |
46 |
Correct |
116 ms |
17236 KB |
Output is correct |
47 |
Correct |
135 ms |
18644 KB |
Output is correct |
48 |
Correct |
169 ms |
21748 KB |
Output is correct |
49 |
Correct |
339 ms |
34488 KB |
Output is correct |
50 |
Correct |
341 ms |
34576 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
9720 KB |
Output is correct |
2 |
Correct |
10 ms |
9720 KB |
Output is correct |
3 |
Correct |
10 ms |
9720 KB |
Output is correct |
4 |
Correct |
10 ms |
9720 KB |
Output is correct |
5 |
Correct |
10 ms |
9720 KB |
Output is correct |
6 |
Correct |
10 ms |
9720 KB |
Output is correct |
7 |
Correct |
10 ms |
9720 KB |
Output is correct |
8 |
Correct |
10 ms |
9720 KB |
Output is correct |
9 |
Correct |
10 ms |
9720 KB |
Output is correct |
10 |
Correct |
10 ms |
9800 KB |
Output is correct |
11 |
Correct |
10 ms |
9760 KB |
Output is correct |
12 |
Correct |
10 ms |
9720 KB |
Output is correct |
13 |
Correct |
10 ms |
9724 KB |
Output is correct |
14 |
Correct |
10 ms |
9720 KB |
Output is correct |
15 |
Correct |
10 ms |
9720 KB |
Output is correct |
16 |
Correct |
10 ms |
9720 KB |
Output is correct |
17 |
Correct |
10 ms |
9720 KB |
Output is correct |
18 |
Correct |
10 ms |
9848 KB |
Output is correct |
19 |
Correct |
10 ms |
9720 KB |
Output is correct |
20 |
Correct |
10 ms |
9724 KB |
Output is correct |
21 |
Correct |
10 ms |
9720 KB |
Output is correct |
22 |
Correct |
10 ms |
9720 KB |
Output is correct |
23 |
Correct |
10 ms |
9720 KB |
Output is correct |
24 |
Correct |
10 ms |
9720 KB |
Output is correct |
25 |
Correct |
10 ms |
9720 KB |
Output is correct |
26 |
Correct |
10 ms |
9720 KB |
Output is correct |
27 |
Correct |
10 ms |
9720 KB |
Output is correct |
28 |
Correct |
10 ms |
9720 KB |
Output is correct |
29 |
Correct |
10 ms |
9820 KB |
Output is correct |
30 |
Correct |
10 ms |
9720 KB |
Output is correct |
31 |
Correct |
10 ms |
9720 KB |
Output is correct |
32 |
Correct |
10 ms |
9720 KB |
Output is correct |
33 |
Correct |
10 ms |
9720 KB |
Output is correct |
34 |
Correct |
10 ms |
9724 KB |
Output is correct |
35 |
Correct |
10 ms |
9692 KB |
Output is correct |
36 |
Correct |
10 ms |
9720 KB |
Output is correct |
37 |
Correct |
10 ms |
9720 KB |
Output is correct |
38 |
Correct |
12 ms |
9720 KB |
Output is correct |
39 |
Correct |
10 ms |
9720 KB |
Output is correct |
40 |
Correct |
10 ms |
9720 KB |
Output is correct |
41 |
Correct |
13 ms |
9720 KB |
Output is correct |
42 |
Correct |
10 ms |
9720 KB |
Output is correct |
43 |
Correct |
10 ms |
9720 KB |
Output is correct |
44 |
Correct |
10 ms |
9720 KB |
Output is correct |
45 |
Correct |
10 ms |
9720 KB |
Output is correct |
46 |
Correct |
10 ms |
9720 KB |
Output is correct |
47 |
Correct |
10 ms |
9720 KB |
Output is correct |
48 |
Correct |
10 ms |
9720 KB |
Output is correct |
49 |
Correct |
10 ms |
9720 KB |
Output is correct |
50 |
Correct |
10 ms |
9720 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
9720 KB |
Output is correct |
2 |
Correct |
10 ms |
9720 KB |
Output is correct |
3 |
Correct |
10 ms |
9720 KB |
Output is correct |
4 |
Correct |
10 ms |
9720 KB |
Output is correct |
5 |
Correct |
10 ms |
9720 KB |
Output is correct |
6 |
Correct |
10 ms |
9720 KB |
Output is correct |
7 |
Correct |
10 ms |
9720 KB |
Output is correct |
8 |
Correct |
10 ms |
9720 KB |
Output is correct |
9 |
Correct |
10 ms |
9720 KB |
Output is correct |
10 |
Correct |
10 ms |
9800 KB |
Output is correct |
11 |
Correct |
10 ms |
9760 KB |
Output is correct |
12 |
Correct |
10 ms |
9720 KB |
Output is correct |
13 |
Correct |
10 ms |
9724 KB |
Output is correct |
14 |
Correct |
10 ms |
9720 KB |
Output is correct |
15 |
Correct |
10 ms |
9720 KB |
Output is correct |
16 |
Correct |
10 ms |
9720 KB |
Output is correct |
17 |
Correct |
10 ms |
9720 KB |
Output is correct |
18 |
Correct |
10 ms |
9848 KB |
Output is correct |
19 |
Correct |
10 ms |
9720 KB |
Output is correct |
20 |
Correct |
10 ms |
9724 KB |
Output is correct |
21 |
Correct |
10 ms |
9720 KB |
Output is correct |
22 |
Correct |
10 ms |
9720 KB |
Output is correct |
23 |
Correct |
10 ms |
9720 KB |
Output is correct |
24 |
Correct |
10 ms |
9720 KB |
Output is correct |
25 |
Correct |
10 ms |
9720 KB |
Output is correct |
26 |
Correct |
11 ms |
9848 KB |
Output is correct |
27 |
Correct |
14 ms |
9976 KB |
Output is correct |
28 |
Correct |
14 ms |
9976 KB |
Output is correct |
29 |
Correct |
48 ms |
12756 KB |
Output is correct |
30 |
Correct |
50 ms |
12664 KB |
Output is correct |
31 |
Correct |
249 ms |
30796 KB |
Output is correct |
32 |
Correct |
34 ms |
10744 KB |
Output is correct |
33 |
Correct |
78 ms |
14836 KB |
Output is correct |
34 |
Correct |
82 ms |
15476 KB |
Output is correct |
35 |
Correct |
77 ms |
14708 KB |
Output is correct |
36 |
Correct |
56 ms |
13616 KB |
Output is correct |
37 |
Correct |
36 ms |
10948 KB |
Output is correct |
38 |
Correct |
74 ms |
14196 KB |
Output is correct |
39 |
Correct |
67 ms |
14708 KB |
Output is correct |
40 |
Correct |
34 ms |
10744 KB |
Output is correct |
41 |
Correct |
57 ms |
12792 KB |
Output is correct |
42 |
Correct |
56 ms |
12792 KB |
Output is correct |
43 |
Correct |
77 ms |
14712 KB |
Output is correct |
44 |
Correct |
74 ms |
14356 KB |
Output is correct |
45 |
Correct |
63 ms |
13556 KB |
Output is correct |
46 |
Correct |
116 ms |
17236 KB |
Output is correct |
47 |
Correct |
135 ms |
18644 KB |
Output is correct |
48 |
Correct |
169 ms |
21748 KB |
Output is correct |
49 |
Correct |
339 ms |
34488 KB |
Output is correct |
50 |
Correct |
341 ms |
34576 KB |
Output is correct |
51 |
Correct |
10 ms |
9720 KB |
Output is correct |
52 |
Correct |
10 ms |
9720 KB |
Output is correct |
53 |
Correct |
10 ms |
9720 KB |
Output is correct |
54 |
Correct |
10 ms |
9820 KB |
Output is correct |
55 |
Correct |
10 ms |
9720 KB |
Output is correct |
56 |
Correct |
10 ms |
9720 KB |
Output is correct |
57 |
Correct |
10 ms |
9720 KB |
Output is correct |
58 |
Correct |
10 ms |
9720 KB |
Output is correct |
59 |
Correct |
10 ms |
9724 KB |
Output is correct |
60 |
Correct |
10 ms |
9692 KB |
Output is correct |
61 |
Correct |
10 ms |
9720 KB |
Output is correct |
62 |
Correct |
10 ms |
9720 KB |
Output is correct |
63 |
Correct |
12 ms |
9720 KB |
Output is correct |
64 |
Correct |
10 ms |
9720 KB |
Output is correct |
65 |
Correct |
10 ms |
9720 KB |
Output is correct |
66 |
Correct |
13 ms |
9720 KB |
Output is correct |
67 |
Correct |
10 ms |
9720 KB |
Output is correct |
68 |
Correct |
10 ms |
9720 KB |
Output is correct |
69 |
Correct |
10 ms |
9720 KB |
Output is correct |
70 |
Correct |
10 ms |
9720 KB |
Output is correct |
71 |
Correct |
10 ms |
9720 KB |
Output is correct |
72 |
Correct |
10 ms |
9720 KB |
Output is correct |
73 |
Correct |
10 ms |
9720 KB |
Output is correct |
74 |
Correct |
10 ms |
9720 KB |
Output is correct |
75 |
Correct |
10 ms |
9720 KB |
Output is correct |
76 |
Incorrect |
13 ms |
9976 KB |
Output isn't correct |
77 |
Halted |
0 ms |
0 KB |
- |