# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
128585 |
2019-07-11T07:11:36 Z |
조승현(#3164) |
None (JOI16_ho_t4) |
C++14 |
|
182 ms |
25548 KB |
#include<cstdio>
#include<algorithm>
#include<map>
#include<vector>
using namespace std;
#define pii pair<int,int>
#define pll pair<long long, long long>
int n, K;
char p[101000];
map<pii, int>Map;
struct point {
int x, y;
};
int cnt = 0;
vector<int>G[101000];
map<pll, int>vis;
vector<point> TP;
point U[101000];
long long XX, YY, Mod;
pll Make(long long a, long long b) {
return { -YY * a + XX * b, XX*a + YY * b };
}
pll Make2(long long a, long long b) {
return { -YY * a + XX * b, (XX*a + YY * b) % Mod };
}
struct Range {
int b, e;
};
vector<Range>GG[101000];
long long Ans;
void Go(vector<Range> *P) {
int i, pv[4] = { 0,0,0,0 }, sz[4];
for (i = 0; i < 4; i++)sz[i] = P[i].size();
while (1) {
int r1 = 1e9, r2 = -1e9;
for (i = 0; i < 4; i++) {
r1 = min(r1, P[i][pv[i]].e);
r2 = max(r2, P[i][pv[i]].b);
}
if (r1 >= r2)Ans += r1 - r2 + 1;
int Mn = 1e9, x = -1;
for (i = 0; i < 4; i++) {
if (pv[i] < sz[i] - 1 && P[i][pv[i]].e < Mn) {
Mn = P[i][pv[i]].e;
x = i;
}
}
if (x == -1)break;
pv[x]++;
}
}
void Calc(vector<int> &P, vector<Range> &Q) {
int i;
int b = -1, e = -1;
for (auto &t : P) {
if (e < t) {
if (e != -1)Q.push_back({ b,e });
b = t;
e = t + K - 1;
}
e = max(e, t + K - 1);
}
Q.push_back({ b,e });
}
int main() {
int i, j, x = 0, y = 0;
scanf("%d%d", &n, &K);
scanf("%s", p);
Map[{0, 0}] = 1;
for (i = 0; i < n; i++) {
if (p[i] == 'E')x++;
if (p[i] == 'W')x--;
if (p[i] == 'N')y++;
if (p[i] == 'S')y--;
Map[{x, y}] = 1;
}
if (x == 0 && y == 0) {
int res = 0;
for (auto &t : Map) {
int x = t.first.first, y = t.first.second;
if (Map[{x, y}] == 1 && Map[{x + 1, y}] == 1 && Map[{x, y + 1}] == 1 && Map[{x + 1, y + 1}] == 1)res++;
}
printf("%d\n", res);
return 0;
}
for (auto &t : Map)TP.push_back({ t.first.first, t.first.second });
if (x < 0) {
for (auto &t : TP)t.x = -t.x;
x = -x;
}
if (y < 0) {
for (auto &t : TP)t.y = -t.y;
y = -y;
}
for (auto &t : TP)t.x += n + 1, t.y += n + 1;
Mod = 1ll * x*x + 1ll * y*y;
XX = x, YY = y;
for (auto &t : TP) {
pll pp = Make(t.x, t.y);
pll pp2 = { pp.first, pp.second%Mod };
if (!vis.count(pp2)) {
vis[pp2] = ++cnt;
U[cnt] = t;
}
G[vis[pp2]].push_back(pp.second / Mod);
}
for (i = 1; i <= cnt; i++) {
sort(G[i].begin(), G[i].end());
Calc(G[i], GG[i]);
}
for (i = 1; i <= cnt; i++) {
point t = U[i];
pll pp1 = Make2(t.x, t.y);
pll pp2 = Make2(t.x + 1, t.y);
pll pp3 = Make2(t.x, t.y + 1);
pll pp4 = Make2(t.x + 1, t.y + 1);
if (!vis.count(pp1) || !vis.count(pp2) || !vis.count(pp3) || !vis.count(pp4))continue;
long long a1 = Make(t.x, t.y).second / Mod;
long long a2 = Make(t.x + 1, t.y).second / Mod;
long long a3 = Make(t.x, t.y + 1).second / Mod;
long long a4 = Make(t.x + 1, t.y + 1).second / Mod;
vector<Range>P[4];
P[0] = GG[vis[pp1]];
P[1] = GG[vis[pp2]];
P[2] = GG[vis[pp3]];
P[3] = GG[vis[pp4]];
for (auto &t : P[1])t.b -= a2 - a1, t.e -= a2 - a1;
for (auto &t : P[2])t.b -= a3 - a1, t.e -= a3 - a1;
for (auto &t : P[3])t.b -= a4 - a1, t.e -= a4 - a1;
Go(P);
}
printf("%lld\n", Ans);
}
Compilation message
2016_ho_t4.cpp: In function 'void Calc(std::vector<int>&, std::vector<Range>&)':
2016_ho_t4.cpp:53:6: warning: unused variable 'i' [-Wunused-variable]
int i;
^
2016_ho_t4.cpp: In function 'int main()':
2016_ho_t4.cpp:66:9: warning: unused variable 'j' [-Wunused-variable]
int i, j, x = 0, y = 0;
^
2016_ho_t4.cpp:67: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:68:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%s", p);
~~~~~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
4984 KB |
Output is correct |
2 |
Correct |
6 ms |
5116 KB |
Output is correct |
3 |
Correct |
6 ms |
4984 KB |
Output is correct |
4 |
Correct |
6 ms |
4984 KB |
Output is correct |
5 |
Correct |
6 ms |
5112 KB |
Output is correct |
6 |
Correct |
6 ms |
4984 KB |
Output is correct |
7 |
Correct |
6 ms |
4984 KB |
Output is correct |
8 |
Correct |
6 ms |
4984 KB |
Output is correct |
9 |
Correct |
6 ms |
4984 KB |
Output is correct |
10 |
Correct |
6 ms |
5112 KB |
Output is correct |
11 |
Correct |
6 ms |
4984 KB |
Output is correct |
12 |
Correct |
6 ms |
4984 KB |
Output is correct |
13 |
Correct |
6 ms |
4984 KB |
Output is correct |
14 |
Correct |
6 ms |
4984 KB |
Output is correct |
15 |
Correct |
6 ms |
4984 KB |
Output is correct |
16 |
Correct |
6 ms |
4984 KB |
Output is correct |
17 |
Correct |
6 ms |
5112 KB |
Output is correct |
18 |
Correct |
6 ms |
5112 KB |
Output is correct |
19 |
Correct |
6 ms |
4984 KB |
Output is correct |
20 |
Correct |
6 ms |
4984 KB |
Output is correct |
21 |
Correct |
6 ms |
4984 KB |
Output is correct |
22 |
Correct |
6 ms |
4984 KB |
Output is correct |
23 |
Correct |
6 ms |
4984 KB |
Output is correct |
24 |
Correct |
6 ms |
5112 KB |
Output is correct |
25 |
Correct |
6 ms |
5112 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
4984 KB |
Output is correct |
2 |
Correct |
6 ms |
5116 KB |
Output is correct |
3 |
Correct |
6 ms |
4984 KB |
Output is correct |
4 |
Correct |
6 ms |
4984 KB |
Output is correct |
5 |
Correct |
6 ms |
5112 KB |
Output is correct |
6 |
Correct |
6 ms |
4984 KB |
Output is correct |
7 |
Correct |
6 ms |
4984 KB |
Output is correct |
8 |
Correct |
6 ms |
4984 KB |
Output is correct |
9 |
Correct |
6 ms |
4984 KB |
Output is correct |
10 |
Correct |
6 ms |
5112 KB |
Output is correct |
11 |
Correct |
6 ms |
4984 KB |
Output is correct |
12 |
Correct |
6 ms |
4984 KB |
Output is correct |
13 |
Correct |
6 ms |
4984 KB |
Output is correct |
14 |
Correct |
6 ms |
4984 KB |
Output is correct |
15 |
Correct |
6 ms |
4984 KB |
Output is correct |
16 |
Correct |
6 ms |
4984 KB |
Output is correct |
17 |
Correct |
6 ms |
5112 KB |
Output is correct |
18 |
Correct |
6 ms |
5112 KB |
Output is correct |
19 |
Correct |
6 ms |
4984 KB |
Output is correct |
20 |
Correct |
6 ms |
4984 KB |
Output is correct |
21 |
Correct |
6 ms |
4984 KB |
Output is correct |
22 |
Correct |
6 ms |
4984 KB |
Output is correct |
23 |
Correct |
6 ms |
4984 KB |
Output is correct |
24 |
Correct |
6 ms |
5112 KB |
Output is correct |
25 |
Correct |
6 ms |
5112 KB |
Output is correct |
26 |
Correct |
6 ms |
5112 KB |
Output is correct |
27 |
Correct |
9 ms |
5368 KB |
Output is correct |
28 |
Correct |
10 ms |
5368 KB |
Output is correct |
29 |
Correct |
36 ms |
7908 KB |
Output is correct |
30 |
Correct |
36 ms |
7800 KB |
Output is correct |
31 |
Correct |
150 ms |
22120 KB |
Output is correct |
32 |
Correct |
28 ms |
6620 KB |
Output is correct |
33 |
Correct |
64 ms |
10232 KB |
Output is correct |
34 |
Correct |
63 ms |
10344 KB |
Output is correct |
35 |
Correct |
60 ms |
9844 KB |
Output is correct |
36 |
Correct |
40 ms |
8436 KB |
Output is correct |
37 |
Correct |
28 ms |
6904 KB |
Output is correct |
38 |
Correct |
57 ms |
9592 KB |
Output is correct |
39 |
Correct |
50 ms |
9972 KB |
Output is correct |
40 |
Correct |
26 ms |
6648 KB |
Output is correct |
41 |
Correct |
33 ms |
7412 KB |
Output is correct |
42 |
Correct |
41 ms |
8056 KB |
Output is correct |
43 |
Correct |
60 ms |
9884 KB |
Output is correct |
44 |
Correct |
61 ms |
9848 KB |
Output is correct |
45 |
Correct |
48 ms |
9080 KB |
Output is correct |
46 |
Correct |
82 ms |
12016 KB |
Output is correct |
47 |
Correct |
129 ms |
15360 KB |
Output is correct |
48 |
Correct |
54 ms |
15080 KB |
Output is correct |
49 |
Correct |
182 ms |
25548 KB |
Output is correct |
50 |
Correct |
169 ms |
25524 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
4984 KB |
Output is correct |
2 |
Correct |
6 ms |
5116 KB |
Output is correct |
3 |
Correct |
6 ms |
4984 KB |
Output is correct |
4 |
Correct |
6 ms |
4984 KB |
Output is correct |
5 |
Correct |
6 ms |
5112 KB |
Output is correct |
6 |
Correct |
6 ms |
4984 KB |
Output is correct |
7 |
Correct |
6 ms |
4984 KB |
Output is correct |
8 |
Correct |
6 ms |
4984 KB |
Output is correct |
9 |
Correct |
6 ms |
4984 KB |
Output is correct |
10 |
Correct |
6 ms |
5112 KB |
Output is correct |
11 |
Correct |
6 ms |
4984 KB |
Output is correct |
12 |
Correct |
6 ms |
4984 KB |
Output is correct |
13 |
Correct |
6 ms |
4984 KB |
Output is correct |
14 |
Correct |
6 ms |
4984 KB |
Output is correct |
15 |
Correct |
6 ms |
4984 KB |
Output is correct |
16 |
Correct |
6 ms |
4984 KB |
Output is correct |
17 |
Correct |
6 ms |
5112 KB |
Output is correct |
18 |
Correct |
6 ms |
5112 KB |
Output is correct |
19 |
Correct |
6 ms |
4984 KB |
Output is correct |
20 |
Correct |
6 ms |
4984 KB |
Output is correct |
21 |
Correct |
6 ms |
4984 KB |
Output is correct |
22 |
Correct |
6 ms |
4984 KB |
Output is correct |
23 |
Correct |
6 ms |
4984 KB |
Output is correct |
24 |
Correct |
6 ms |
5112 KB |
Output is correct |
25 |
Correct |
6 ms |
5112 KB |
Output is correct |
26 |
Correct |
6 ms |
5112 KB |
Output is correct |
27 |
Correct |
6 ms |
5112 KB |
Output is correct |
28 |
Correct |
6 ms |
4984 KB |
Output is correct |
29 |
Correct |
6 ms |
5112 KB |
Output is correct |
30 |
Correct |
6 ms |
4984 KB |
Output is correct |
31 |
Correct |
6 ms |
5112 KB |
Output is correct |
32 |
Correct |
6 ms |
5112 KB |
Output is correct |
33 |
Incorrect |
6 ms |
5112 KB |
Output isn't correct |
34 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
4984 KB |
Output is correct |
2 |
Correct |
6 ms |
5116 KB |
Output is correct |
3 |
Correct |
6 ms |
4984 KB |
Output is correct |
4 |
Correct |
6 ms |
4984 KB |
Output is correct |
5 |
Correct |
6 ms |
5112 KB |
Output is correct |
6 |
Correct |
6 ms |
4984 KB |
Output is correct |
7 |
Correct |
6 ms |
4984 KB |
Output is correct |
8 |
Correct |
6 ms |
4984 KB |
Output is correct |
9 |
Correct |
6 ms |
4984 KB |
Output is correct |
10 |
Correct |
6 ms |
5112 KB |
Output is correct |
11 |
Correct |
6 ms |
4984 KB |
Output is correct |
12 |
Correct |
6 ms |
4984 KB |
Output is correct |
13 |
Correct |
6 ms |
4984 KB |
Output is correct |
14 |
Correct |
6 ms |
4984 KB |
Output is correct |
15 |
Correct |
6 ms |
4984 KB |
Output is correct |
16 |
Correct |
6 ms |
4984 KB |
Output is correct |
17 |
Correct |
6 ms |
5112 KB |
Output is correct |
18 |
Correct |
6 ms |
5112 KB |
Output is correct |
19 |
Correct |
6 ms |
4984 KB |
Output is correct |
20 |
Correct |
6 ms |
4984 KB |
Output is correct |
21 |
Correct |
6 ms |
4984 KB |
Output is correct |
22 |
Correct |
6 ms |
4984 KB |
Output is correct |
23 |
Correct |
6 ms |
4984 KB |
Output is correct |
24 |
Correct |
6 ms |
5112 KB |
Output is correct |
25 |
Correct |
6 ms |
5112 KB |
Output is correct |
26 |
Correct |
6 ms |
5112 KB |
Output is correct |
27 |
Correct |
9 ms |
5368 KB |
Output is correct |
28 |
Correct |
10 ms |
5368 KB |
Output is correct |
29 |
Correct |
36 ms |
7908 KB |
Output is correct |
30 |
Correct |
36 ms |
7800 KB |
Output is correct |
31 |
Correct |
150 ms |
22120 KB |
Output is correct |
32 |
Correct |
28 ms |
6620 KB |
Output is correct |
33 |
Correct |
64 ms |
10232 KB |
Output is correct |
34 |
Correct |
63 ms |
10344 KB |
Output is correct |
35 |
Correct |
60 ms |
9844 KB |
Output is correct |
36 |
Correct |
40 ms |
8436 KB |
Output is correct |
37 |
Correct |
28 ms |
6904 KB |
Output is correct |
38 |
Correct |
57 ms |
9592 KB |
Output is correct |
39 |
Correct |
50 ms |
9972 KB |
Output is correct |
40 |
Correct |
26 ms |
6648 KB |
Output is correct |
41 |
Correct |
33 ms |
7412 KB |
Output is correct |
42 |
Correct |
41 ms |
8056 KB |
Output is correct |
43 |
Correct |
60 ms |
9884 KB |
Output is correct |
44 |
Correct |
61 ms |
9848 KB |
Output is correct |
45 |
Correct |
48 ms |
9080 KB |
Output is correct |
46 |
Correct |
82 ms |
12016 KB |
Output is correct |
47 |
Correct |
129 ms |
15360 KB |
Output is correct |
48 |
Correct |
54 ms |
15080 KB |
Output is correct |
49 |
Correct |
182 ms |
25548 KB |
Output is correct |
50 |
Correct |
169 ms |
25524 KB |
Output is correct |
51 |
Correct |
6 ms |
5112 KB |
Output is correct |
52 |
Correct |
6 ms |
5112 KB |
Output is correct |
53 |
Correct |
6 ms |
4984 KB |
Output is correct |
54 |
Correct |
6 ms |
5112 KB |
Output is correct |
55 |
Correct |
6 ms |
4984 KB |
Output is correct |
56 |
Correct |
6 ms |
5112 KB |
Output is correct |
57 |
Correct |
6 ms |
5112 KB |
Output is correct |
58 |
Incorrect |
6 ms |
5112 KB |
Output isn't correct |
59 |
Halted |
0 ms |
0 KB |
- |