Submission #51183

# Submission time Handle Problem Language Result Execution time Memory
51183 2018-06-17T06:27:39 Z 노영훈(#1283, Diuven) None (JOI16_ho_t4) C++11
15 / 100
174 ms 21176 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pii;
const int MX=100010, inf=2e9;

int n, k;
char S[MX];

ll cnt(map<pii, bool> &B){
    ll ret=0;
    map<pii, bool> C;
    vector<pii> V;
    for(auto &p:B)
        V.push_back(p.first);
    for(pii &p:V){
        ll x, y; tie(x,y)=p;
        if(!C[p] && B[pii(x,y+1)] && B[pii(x+1,y)] && B[pii(x+1, y+1)]) ret++;
        C[p]=true;
    }
    return ret;
}

void walk(map<pii, bool> &B, ll x=0, ll y=0){
    B[pii(0,0)]=true;
    for(int i=1; i<=n; i++){
        if(S[i]=='N') y++;
        if(S[i]=='S') y--;
        if(S[i]=='E') x++;
        if(S[i]=='W') x--;
        B[pii(x,y)]=true;
    }
}

pii walk(){
    int x=0, y=0;
    for(int i=1; i<=n; i++){
        if(S[i]=='N') y++;
        if(S[i]=='S') y--;
        if(S[i]=='E') x++;
        if(S[i]=='W') x--;
    }
    return pii(x,y);
}

ll solve1(){
    map<pii, bool> B;
    walk(B);
    return cnt(B);
}

ll solve2(){
    map<pii, bool> B;
    ll a,b; tie(a,b)=walk();
    if(a==0 && b==0){
        walk(B);
        return cnt(B);
    }
    ll C[105]={};
    for(int i=1; i<=2*n; i++){
        walk(B, a*(i-1), b*(i-1));
        C[i]=cnt(B);
    }
    if(k<=2*n) return C[k];
    return C[2*n] + (C[2*n]-C[2*n-1]) * (k-2*n);
}

int main(){
    ios::sync_with_stdio(0); cin.tie(0);
    cin>>n>>k;
    cin>>(S+1);
    if(k==1){
        cout<<solve1();
    }
    else{
        cout<<solve2();
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
3 Correct 2 ms 412 KB Output is correct
4 Correct 3 ms 468 KB Output is correct
5 Correct 3 ms 468 KB Output is correct
6 Correct 2 ms 468 KB Output is correct
7 Correct 2 ms 544 KB Output is correct
8 Correct 2 ms 544 KB Output is correct
9 Correct 2 ms 544 KB Output is correct
10 Correct 2 ms 548 KB Output is correct
11 Correct 2 ms 620 KB Output is correct
12 Correct 2 ms 620 KB Output is correct
13 Correct 2 ms 620 KB Output is correct
14 Correct 2 ms 620 KB Output is correct
15 Correct 2 ms 620 KB Output is correct
16 Correct 2 ms 620 KB Output is correct
17 Correct 2 ms 640 KB Output is correct
18 Correct 2 ms 640 KB Output is correct
19 Correct 2 ms 640 KB Output is correct
20 Correct 2 ms 640 KB Output is correct
21 Correct 2 ms 640 KB Output is correct
22 Correct 2 ms 640 KB Output is correct
23 Correct 2 ms 640 KB Output is correct
24 Correct 2 ms 640 KB Output is correct
25 Correct 2 ms 724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
3 Correct 2 ms 412 KB Output is correct
4 Correct 3 ms 468 KB Output is correct
5 Correct 3 ms 468 KB Output is correct
6 Correct 2 ms 468 KB Output is correct
7 Correct 2 ms 544 KB Output is correct
8 Correct 2 ms 544 KB Output is correct
9 Correct 2 ms 544 KB Output is correct
10 Correct 2 ms 548 KB Output is correct
11 Correct 2 ms 620 KB Output is correct
12 Correct 2 ms 620 KB Output is correct
13 Correct 2 ms 620 KB Output is correct
14 Correct 2 ms 620 KB Output is correct
15 Correct 2 ms 620 KB Output is correct
16 Correct 2 ms 620 KB Output is correct
17 Correct 2 ms 640 KB Output is correct
18 Correct 2 ms 640 KB Output is correct
19 Correct 2 ms 640 KB Output is correct
20 Correct 2 ms 640 KB Output is correct
21 Correct 2 ms 640 KB Output is correct
22 Correct 2 ms 640 KB Output is correct
23 Correct 2 ms 640 KB Output is correct
24 Correct 2 ms 640 KB Output is correct
25 Correct 2 ms 724 KB Output is correct
26 Correct 3 ms 724 KB Output is correct
27 Correct 4 ms 856 KB Output is correct
28 Correct 6 ms 1260 KB Output is correct
29 Correct 20 ms 2916 KB Output is correct
30 Correct 19 ms 3048 KB Output is correct
31 Correct 135 ms 17700 KB Output is correct
32 Correct 32 ms 17700 KB Output is correct
33 Correct 30 ms 17700 KB Output is correct
34 Correct 40 ms 17700 KB Output is correct
35 Correct 35 ms 17700 KB Output is correct
36 Correct 27 ms 17700 KB Output is correct
37 Correct 29 ms 17700 KB Output is correct
38 Correct 31 ms 17700 KB Output is correct
39 Correct 33 ms 17700 KB Output is correct
40 Correct 32 ms 17700 KB Output is correct
41 Correct 29 ms 17700 KB Output is correct
42 Correct 21 ms 17700 KB Output is correct
43 Correct 32 ms 17700 KB Output is correct
44 Correct 28 ms 17700 KB Output is correct
45 Correct 25 ms 17700 KB Output is correct
46 Correct 77 ms 17700 KB Output is correct
47 Correct 74 ms 17700 KB Output is correct
48 Correct 121 ms 21028 KB Output is correct
49 Correct 166 ms 21096 KB Output is correct
50 Correct 174 ms 21176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
3 Correct 2 ms 412 KB Output is correct
4 Correct 3 ms 468 KB Output is correct
5 Correct 3 ms 468 KB Output is correct
6 Correct 2 ms 468 KB Output is correct
7 Correct 2 ms 544 KB Output is correct
8 Correct 2 ms 544 KB Output is correct
9 Correct 2 ms 544 KB Output is correct
10 Correct 2 ms 548 KB Output is correct
11 Correct 2 ms 620 KB Output is correct
12 Correct 2 ms 620 KB Output is correct
13 Correct 2 ms 620 KB Output is correct
14 Correct 2 ms 620 KB Output is correct
15 Correct 2 ms 620 KB Output is correct
16 Correct 2 ms 620 KB Output is correct
17 Correct 2 ms 640 KB Output is correct
18 Correct 2 ms 640 KB Output is correct
19 Correct 2 ms 640 KB Output is correct
20 Correct 2 ms 640 KB Output is correct
21 Correct 2 ms 640 KB Output is correct
22 Correct 2 ms 640 KB Output is correct
23 Correct 2 ms 640 KB Output is correct
24 Correct 2 ms 640 KB Output is correct
25 Correct 2 ms 724 KB Output is correct
26 Incorrect 52 ms 21176 KB Output isn't correct
27 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
3 Correct 2 ms 412 KB Output is correct
4 Correct 3 ms 468 KB Output is correct
5 Correct 3 ms 468 KB Output is correct
6 Correct 2 ms 468 KB Output is correct
7 Correct 2 ms 544 KB Output is correct
8 Correct 2 ms 544 KB Output is correct
9 Correct 2 ms 544 KB Output is correct
10 Correct 2 ms 548 KB Output is correct
11 Correct 2 ms 620 KB Output is correct
12 Correct 2 ms 620 KB Output is correct
13 Correct 2 ms 620 KB Output is correct
14 Correct 2 ms 620 KB Output is correct
15 Correct 2 ms 620 KB Output is correct
16 Correct 2 ms 620 KB Output is correct
17 Correct 2 ms 640 KB Output is correct
18 Correct 2 ms 640 KB Output is correct
19 Correct 2 ms 640 KB Output is correct
20 Correct 2 ms 640 KB Output is correct
21 Correct 2 ms 640 KB Output is correct
22 Correct 2 ms 640 KB Output is correct
23 Correct 2 ms 640 KB Output is correct
24 Correct 2 ms 640 KB Output is correct
25 Correct 2 ms 724 KB Output is correct
26 Correct 3 ms 724 KB Output is correct
27 Correct 4 ms 856 KB Output is correct
28 Correct 6 ms 1260 KB Output is correct
29 Correct 20 ms 2916 KB Output is correct
30 Correct 19 ms 3048 KB Output is correct
31 Correct 135 ms 17700 KB Output is correct
32 Correct 32 ms 17700 KB Output is correct
33 Correct 30 ms 17700 KB Output is correct
34 Correct 40 ms 17700 KB Output is correct
35 Correct 35 ms 17700 KB Output is correct
36 Correct 27 ms 17700 KB Output is correct
37 Correct 29 ms 17700 KB Output is correct
38 Correct 31 ms 17700 KB Output is correct
39 Correct 33 ms 17700 KB Output is correct
40 Correct 32 ms 17700 KB Output is correct
41 Correct 29 ms 17700 KB Output is correct
42 Correct 21 ms 17700 KB Output is correct
43 Correct 32 ms 17700 KB Output is correct
44 Correct 28 ms 17700 KB Output is correct
45 Correct 25 ms 17700 KB Output is correct
46 Correct 77 ms 17700 KB Output is correct
47 Correct 74 ms 17700 KB Output is correct
48 Correct 121 ms 21028 KB Output is correct
49 Correct 166 ms 21096 KB Output is correct
50 Correct 174 ms 21176 KB Output is correct
51 Incorrect 52 ms 21176 KB Output isn't correct
52 Halted 0 ms 0 KB -