Submission #51182

# Submission time Handle Problem Language Result Execution time Memory
51182 2018-06-17T06:19:01 Z 노영훈(#1283, Diuven) None (JOI16_ho_t4) C++11
15 / 100
176 ms 21096 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];

int 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[55]={};
    for(int i=1; i<=n; i++){
        walk(B, a*(i-1), b*(i-1));
        C[i]=cnt(B);
    }
    if(k<=n) return C[k];
    return C[n] + (C[n]-C[n-1]) * (k-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 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 480 KB Output is correct
4 Correct 2 ms 500 KB Output is correct
5 Correct 3 ms 500 KB Output is correct
6 Correct 2 ms 516 KB Output is correct
7 Correct 2 ms 688 KB Output is correct
8 Correct 2 ms 688 KB Output is correct
9 Correct 2 ms 688 KB Output is correct
10 Correct 2 ms 688 KB Output is correct
11 Correct 2 ms 688 KB Output is correct
12 Correct 2 ms 688 KB Output is correct
13 Correct 3 ms 736 KB Output is correct
14 Correct 2 ms 736 KB Output is correct
15 Correct 2 ms 736 KB Output is correct
16 Correct 2 ms 740 KB Output is correct
17 Correct 2 ms 740 KB Output is correct
18 Correct 2 ms 740 KB Output is correct
19 Correct 2 ms 740 KB Output is correct
20 Correct 2 ms 740 KB Output is correct
21 Correct 2 ms 740 KB Output is correct
22 Correct 2 ms 740 KB Output is correct
23 Correct 2 ms 740 KB Output is correct
24 Correct 2 ms 740 KB Output is correct
25 Correct 2 ms 740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 480 KB Output is correct
4 Correct 2 ms 500 KB Output is correct
5 Correct 3 ms 500 KB Output is correct
6 Correct 2 ms 516 KB Output is correct
7 Correct 2 ms 688 KB Output is correct
8 Correct 2 ms 688 KB Output is correct
9 Correct 2 ms 688 KB Output is correct
10 Correct 2 ms 688 KB Output is correct
11 Correct 2 ms 688 KB Output is correct
12 Correct 2 ms 688 KB Output is correct
13 Correct 3 ms 736 KB Output is correct
14 Correct 2 ms 736 KB Output is correct
15 Correct 2 ms 736 KB Output is correct
16 Correct 2 ms 740 KB Output is correct
17 Correct 2 ms 740 KB Output is correct
18 Correct 2 ms 740 KB Output is correct
19 Correct 2 ms 740 KB Output is correct
20 Correct 2 ms 740 KB Output is correct
21 Correct 2 ms 740 KB Output is correct
22 Correct 2 ms 740 KB Output is correct
23 Correct 2 ms 740 KB Output is correct
24 Correct 2 ms 740 KB Output is correct
25 Correct 2 ms 740 KB Output is correct
26 Correct 2 ms 740 KB Output is correct
27 Correct 3 ms 764 KB Output is correct
28 Correct 6 ms 1148 KB Output is correct
29 Correct 20 ms 2808 KB Output is correct
30 Correct 23 ms 2944 KB Output is correct
31 Correct 122 ms 17752 KB Output is correct
32 Correct 27 ms 17752 KB Output is correct
33 Correct 35 ms 17752 KB Output is correct
34 Correct 34 ms 17752 KB Output is correct
35 Correct 31 ms 17752 KB Output is correct
36 Correct 32 ms 17752 KB Output is correct
37 Correct 29 ms 17752 KB Output is correct
38 Correct 29 ms 17752 KB Output is correct
39 Correct 33 ms 17752 KB Output is correct
40 Correct 27 ms 17752 KB Output is correct
41 Correct 24 ms 17752 KB Output is correct
42 Correct 21 ms 17752 KB Output is correct
43 Correct 31 ms 17752 KB Output is correct
44 Correct 28 ms 17752 KB Output is correct
45 Correct 33 ms 17752 KB Output is correct
46 Correct 77 ms 17752 KB Output is correct
47 Correct 85 ms 17752 KB Output is correct
48 Correct 129 ms 21092 KB Output is correct
49 Correct 176 ms 21092 KB Output is correct
50 Correct 169 ms 21096 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 480 KB Output is correct
4 Correct 2 ms 500 KB Output is correct
5 Correct 3 ms 500 KB Output is correct
6 Correct 2 ms 516 KB Output is correct
7 Correct 2 ms 688 KB Output is correct
8 Correct 2 ms 688 KB Output is correct
9 Correct 2 ms 688 KB Output is correct
10 Correct 2 ms 688 KB Output is correct
11 Correct 2 ms 688 KB Output is correct
12 Correct 2 ms 688 KB Output is correct
13 Correct 3 ms 736 KB Output is correct
14 Correct 2 ms 736 KB Output is correct
15 Correct 2 ms 736 KB Output is correct
16 Correct 2 ms 740 KB Output is correct
17 Correct 2 ms 740 KB Output is correct
18 Correct 2 ms 740 KB Output is correct
19 Correct 2 ms 740 KB Output is correct
20 Correct 2 ms 740 KB Output is correct
21 Correct 2 ms 740 KB Output is correct
22 Correct 2 ms 740 KB Output is correct
23 Correct 2 ms 740 KB Output is correct
24 Correct 2 ms 740 KB Output is correct
25 Correct 2 ms 740 KB Output is correct
26 Incorrect 12 ms 21096 KB Output isn't correct
27 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 480 KB Output is correct
4 Correct 2 ms 500 KB Output is correct
5 Correct 3 ms 500 KB Output is correct
6 Correct 2 ms 516 KB Output is correct
7 Correct 2 ms 688 KB Output is correct
8 Correct 2 ms 688 KB Output is correct
9 Correct 2 ms 688 KB Output is correct
10 Correct 2 ms 688 KB Output is correct
11 Correct 2 ms 688 KB Output is correct
12 Correct 2 ms 688 KB Output is correct
13 Correct 3 ms 736 KB Output is correct
14 Correct 2 ms 736 KB Output is correct
15 Correct 2 ms 736 KB Output is correct
16 Correct 2 ms 740 KB Output is correct
17 Correct 2 ms 740 KB Output is correct
18 Correct 2 ms 740 KB Output is correct
19 Correct 2 ms 740 KB Output is correct
20 Correct 2 ms 740 KB Output is correct
21 Correct 2 ms 740 KB Output is correct
22 Correct 2 ms 740 KB Output is correct
23 Correct 2 ms 740 KB Output is correct
24 Correct 2 ms 740 KB Output is correct
25 Correct 2 ms 740 KB Output is correct
26 Correct 2 ms 740 KB Output is correct
27 Correct 3 ms 764 KB Output is correct
28 Correct 6 ms 1148 KB Output is correct
29 Correct 20 ms 2808 KB Output is correct
30 Correct 23 ms 2944 KB Output is correct
31 Correct 122 ms 17752 KB Output is correct
32 Correct 27 ms 17752 KB Output is correct
33 Correct 35 ms 17752 KB Output is correct
34 Correct 34 ms 17752 KB Output is correct
35 Correct 31 ms 17752 KB Output is correct
36 Correct 32 ms 17752 KB Output is correct
37 Correct 29 ms 17752 KB Output is correct
38 Correct 29 ms 17752 KB Output is correct
39 Correct 33 ms 17752 KB Output is correct
40 Correct 27 ms 17752 KB Output is correct
41 Correct 24 ms 17752 KB Output is correct
42 Correct 21 ms 17752 KB Output is correct
43 Correct 31 ms 17752 KB Output is correct
44 Correct 28 ms 17752 KB Output is correct
45 Correct 33 ms 17752 KB Output is correct
46 Correct 77 ms 17752 KB Output is correct
47 Correct 85 ms 17752 KB Output is correct
48 Correct 129 ms 21092 KB Output is correct
49 Correct 176 ms 21092 KB Output is correct
50 Correct 169 ms 21096 KB Output is correct
51 Incorrect 12 ms 21096 KB Output isn't correct
52 Halted 0 ms 0 KB -