Submission #51181

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

int n, k;
char S[MX];

int cnt(map<pii, bool> &B){
    int ret=0;
    map<pii, bool> C;
    vector<pii> V;
    for(auto &p:B)
        V.push_back(p.first);
    for(pii &p:V){
        int 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, int x=0, int 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;
    int 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 428 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 2 ms 488 KB Output is correct
6 Correct 2 ms 488 KB Output is correct
7 Correct 2 ms 544 KB Output is correct
8 Correct 2 ms 656 KB Output is correct
9 Correct 3 ms 656 KB Output is correct
10 Correct 2 ms 656 KB Output is correct
11 Correct 2 ms 656 KB Output is correct
12 Correct 2 ms 656 KB Output is correct
13 Correct 2 ms 656 KB Output is correct
14 Correct 3 ms 656 KB Output is correct
15 Correct 2 ms 656 KB Output is correct
16 Correct 2 ms 724 KB Output is correct
17 Correct 2 ms 724 KB Output is correct
18 Correct 2 ms 724 KB Output is correct
19 Correct 2 ms 724 KB Output is correct
20 Correct 2 ms 724 KB Output is correct
21 Correct 2 ms 724 KB Output is correct
22 Correct 2 ms 724 KB Output is correct
23 Correct 3 ms 724 KB Output is correct
24 Correct 2 ms 724 KB Output is correct
25 Correct 2 ms 724 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 428 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 2 ms 488 KB Output is correct
6 Correct 2 ms 488 KB Output is correct
7 Correct 2 ms 544 KB Output is correct
8 Correct 2 ms 656 KB Output is correct
9 Correct 3 ms 656 KB Output is correct
10 Correct 2 ms 656 KB Output is correct
11 Correct 2 ms 656 KB Output is correct
12 Correct 2 ms 656 KB Output is correct
13 Correct 2 ms 656 KB Output is correct
14 Correct 3 ms 656 KB Output is correct
15 Correct 2 ms 656 KB Output is correct
16 Correct 2 ms 724 KB Output is correct
17 Correct 2 ms 724 KB Output is correct
18 Correct 2 ms 724 KB Output is correct
19 Correct 2 ms 724 KB Output is correct
20 Correct 2 ms 724 KB Output is correct
21 Correct 2 ms 724 KB Output is correct
22 Correct 2 ms 724 KB Output is correct
23 Correct 3 ms 724 KB Output is correct
24 Correct 2 ms 724 KB Output is correct
25 Correct 2 ms 724 KB Output is correct
26 Correct 2 ms 724 KB Output is correct
27 Correct 3 ms 764 KB Output is correct
28 Correct 5 ms 1148 KB Output is correct
29 Correct 16 ms 2684 KB Output is correct
30 Correct 21 ms 2812 KB Output is correct
31 Correct 117 ms 17012 KB Output is correct
32 Correct 25 ms 17012 KB Output is correct
33 Correct 30 ms 17012 KB Output is correct
34 Correct 31 ms 17012 KB Output is correct
35 Correct 30 ms 17012 KB Output is correct
36 Correct 37 ms 17012 KB Output is correct
37 Correct 39 ms 17012 KB Output is correct
38 Correct 27 ms 17012 KB Output is correct
39 Correct 29 ms 17012 KB Output is correct
40 Correct 27 ms 17012 KB Output is correct
41 Correct 25 ms 17012 KB Output is correct
42 Correct 21 ms 17012 KB Output is correct
43 Correct 33 ms 17012 KB Output is correct
44 Correct 31 ms 17012 KB Output is correct
45 Correct 23 ms 17012 KB Output is correct
46 Correct 92 ms 17012 KB Output is correct
47 Correct 71 ms 17012 KB Output is correct
48 Correct 119 ms 20216 KB Output is correct
49 Correct 161 ms 20288 KB Output is correct
50 Correct 169 ms 20336 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 428 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 2 ms 488 KB Output is correct
6 Correct 2 ms 488 KB Output is correct
7 Correct 2 ms 544 KB Output is correct
8 Correct 2 ms 656 KB Output is correct
9 Correct 3 ms 656 KB Output is correct
10 Correct 2 ms 656 KB Output is correct
11 Correct 2 ms 656 KB Output is correct
12 Correct 2 ms 656 KB Output is correct
13 Correct 2 ms 656 KB Output is correct
14 Correct 3 ms 656 KB Output is correct
15 Correct 2 ms 656 KB Output is correct
16 Correct 2 ms 724 KB Output is correct
17 Correct 2 ms 724 KB Output is correct
18 Correct 2 ms 724 KB Output is correct
19 Correct 2 ms 724 KB Output is correct
20 Correct 2 ms 724 KB Output is correct
21 Correct 2 ms 724 KB Output is correct
22 Correct 2 ms 724 KB Output is correct
23 Correct 3 ms 724 KB Output is correct
24 Correct 2 ms 724 KB Output is correct
25 Correct 2 ms 724 KB Output is correct
26 Incorrect 11 ms 20336 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 428 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 2 ms 488 KB Output is correct
6 Correct 2 ms 488 KB Output is correct
7 Correct 2 ms 544 KB Output is correct
8 Correct 2 ms 656 KB Output is correct
9 Correct 3 ms 656 KB Output is correct
10 Correct 2 ms 656 KB Output is correct
11 Correct 2 ms 656 KB Output is correct
12 Correct 2 ms 656 KB Output is correct
13 Correct 2 ms 656 KB Output is correct
14 Correct 3 ms 656 KB Output is correct
15 Correct 2 ms 656 KB Output is correct
16 Correct 2 ms 724 KB Output is correct
17 Correct 2 ms 724 KB Output is correct
18 Correct 2 ms 724 KB Output is correct
19 Correct 2 ms 724 KB Output is correct
20 Correct 2 ms 724 KB Output is correct
21 Correct 2 ms 724 KB Output is correct
22 Correct 2 ms 724 KB Output is correct
23 Correct 3 ms 724 KB Output is correct
24 Correct 2 ms 724 KB Output is correct
25 Correct 2 ms 724 KB Output is correct
26 Correct 2 ms 724 KB Output is correct
27 Correct 3 ms 764 KB Output is correct
28 Correct 5 ms 1148 KB Output is correct
29 Correct 16 ms 2684 KB Output is correct
30 Correct 21 ms 2812 KB Output is correct
31 Correct 117 ms 17012 KB Output is correct
32 Correct 25 ms 17012 KB Output is correct
33 Correct 30 ms 17012 KB Output is correct
34 Correct 31 ms 17012 KB Output is correct
35 Correct 30 ms 17012 KB Output is correct
36 Correct 37 ms 17012 KB Output is correct
37 Correct 39 ms 17012 KB Output is correct
38 Correct 27 ms 17012 KB Output is correct
39 Correct 29 ms 17012 KB Output is correct
40 Correct 27 ms 17012 KB Output is correct
41 Correct 25 ms 17012 KB Output is correct
42 Correct 21 ms 17012 KB Output is correct
43 Correct 33 ms 17012 KB Output is correct
44 Correct 31 ms 17012 KB Output is correct
45 Correct 23 ms 17012 KB Output is correct
46 Correct 92 ms 17012 KB Output is correct
47 Correct 71 ms 17012 KB Output is correct
48 Correct 119 ms 20216 KB Output is correct
49 Correct 161 ms 20288 KB Output is correct
50 Correct 169 ms 20336 KB Output is correct
51 Incorrect 11 ms 20336 KB Output isn't correct
52 Halted 0 ms 0 KB -