Submission #872376

# Submission time Handle Problem Language Result Execution time Memory
872376 2023-11-13T03:27:33 Z azberjibiou None (JOI16_ho_t4) C++17
100 / 100
127 ms 37608 KB
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define pb push_back
#define lb lower_bound
#define gibon ios::sync_with_stdio(false); cin.tie(0);
#define fi first
#define se second
#define pii pair<int, int>
#define pll pair<ll, ll>
typedef long long ll;
using namespace std;
const int mxN=1000005;
const int mxM=500004;
const int MOD=1'000'000'007;
const ll INF=8e18;
int N, K;
char A[mxN];
pii B[mxN];
map <pii, int> mp;
vector <pii> v1, v2;
vector <pii> ct[mxN];
ll ans;
void make_B(){
    for(int i=1;i<=N;i++){
        if(A[i]=='N')   B[i]=pii(B[i-1].fi, B[i-1].se+1);
        if(A[i]=='S')   B[i]=pii(B[i-1].fi, B[i-1].se-1);
        if(A[i]=='E')   B[i]=pii(B[i-1].fi+1, B[i-1].se);
        if(A[i]=='W')   B[i]=pii(B[i-1].fi-1, B[i-1].se);
    }
}
void solv_00(){
    for(int i=0;i<N;i++){
        mp[B[i]]=1;
        v2.push_back(B[i]);
        v2.emplace_back(B[i].fi-1, B[i].se);
        v2.emplace_back(B[i].fi, B[i].se-1);
        v2.emplace_back(B[i].fi-1, B[i].se-1);
    }
    sort(all(v2));
    v2.erase(unique(all(v2)), v2.end());
    for(auto [x, y] : v2){
        if(mp[pii(x, y)]==1 && mp[pii(x+1, y)]==1 && mp[pii(x, y+1)]==1 && mp[pii(x+1, y+1)]==1)    ans++;
    }
    cout << ans;
}
void swap_xy(){
    for(int i=1;i<=N;i++){
        if(A[i]=='N')   A[i]='E';
        else if(A[i]=='S')  A[i]='W';
        else if(A[i]=='E')  A[i]='N';
        else    A[i]='S';
    }
    make_B();
}
void swap_x(){
    for(int i=1;i<=N;i++){
        if(A[i]=='E')   A[i]='W';
        else if(A[i]=='W')  A[i]='E';
    }
    make_B();
}
pair<pii, int> f(int x, int y){
    int q;
    if(x>0) q=x/B[N].fi;
    else if((-x)%B[N].fi==0)    q=-((-x)/B[N].fi);
    else    q=-((-x)/B[N].fi+1);
    return pair<pii, int>(pii(x-q*B[N].fi, y-q*B[N].se), q);
}
pair<pii, int> f(pii p){
    auto [x, y]=p;
    return f(x, y);
}
int main()
{
    gibon
    cin >> N >> K;
    cin >> A+1;
    make_B();
    if(B[N]==pii(0, 0)){
        solv_00();
        return 0;
    }
    if(B[N].fi==0)  swap_xy();
    if(B[N].fi<0)   swap_x();
    for(int i=0;i<=N;i++){
        v1.push_back(f(B[i]).fi);
        v2.push_back(f(B[i]).fi);
        v2.push_back(f(pii(B[i].fi-1, B[i].se)).fi);
        v2.push_back(f(pii(B[i].fi, B[i].se-1)).fi);
        v2.push_back(f(pii(B[i].fi-1, B[i].se-1)).fi);
    }
    sort(all(v1));
    v1.erase(unique(all(v1)), v1.end());
    sort(all(v2));
    v2.erase(unique(all(v2)), v2.end());
    //printf("v1: \n");
    //for(auto [x, y] : v1)   printf("%d %d\n", x, y);
    //printf("----------------------\n");
    for(int i=0;i<=N;i++){
        pii now=f(B[i]).fi;
        int del=f(B[i]).se;
        int ix=lower_bound(all(v1), now)-v1.begin();
        ct[ix].emplace_back(del, 1);
        ct[ix].emplace_back(del+K, -1);
    }
    for(int i=0;i<v1.size();i++)    sort(all(ct[i]));
    //for(int i=0;i<v1.size();i++){
    //    printf("x, y=%d %d: ", v1[i].fi, v1[i].se);
    //    for(auto [x, y] : ct[i])    printf("(%d %d) ", x, y);
    //    printf("\n");
    //}
    //printf("----------------\n");
    for(auto [x, y] : v2){
        //printf("x=%d, y=%d\n", x, y);
        pii n[4]={f(x, y).fi, f(x+1, y).fi, f(x, y+1).fi, f(x+1, y+1).fi}, idx[4];
        int cnt[4]={};
        idx[0].se=f(x, y).se;
        idx[1].se=f(x+1, y).se;
        idx[2].se=f(x, y+1).se;
        idx[3].se=f(x+1, y+1).se;
        bool jog=true;
        for(int i=0;i<4;i++){
            int ti=lower_bound(all(v1), n[i])-v1.begin();
            if(ti==v1.size() || v1[ti]!=n[i])   jog=false;
            idx[i].fi=lower_bound(all(v1), n[i])-v1.begin();
        }
        if(!jog)    continue;
        vector <pair<pii, int>> nct;
        for(int i=0;i<4;i++){
            for(auto [pos, typ] : ct[idx[i].fi])  nct.emplace_back(pii(pos-idx[i].se, typ), i);
        }
        sort(all(nct));
        //for(int i=0;i<nct.size();i++){
        //    printf("(%d %d %d) ", nct[i].fi.fi, nct[i].fi.se, nct[i].se);
        //}
        //printf("\n");
        for(int i=0;i+1<nct.size();i++){
            auto [pos, pm]=nct[i].fi;
            int num=nct[i].se;
            cnt[num]+=pm;
            if(cnt[0]>0 && cnt[1]>0 && cnt[2]>0 && cnt[3]>0)    ans+=nct[i+1].fi.fi-nct[i].fi.fi;
        }
        //printf("ans=%lld\n", ans);
    }
    cout << ans;
}

Compilation message

2016_ho_t4.cpp: In function 'int main()':
2016_ho_t4.cpp:77:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   77 |     cin >> A+1;
      |            ~^~
2016_ho_t4.cpp:106:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  106 |     for(int i=0;i<v1.size();i++)    sort(all(ct[i]));
      |                 ~^~~~~~~~~~
2016_ho_t4.cpp:124:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  124 |             if(ti==v1.size() || v1[ti]!=n[i])   jog=false;
      |                ~~^~~~~~~~~~~
2016_ho_t4.cpp:137:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<int, int>, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  137 |         for(int i=0;i+1<nct.size();i++){
      |                     ~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 25180 KB Output is correct
2 Correct 6 ms 25508 KB Output is correct
3 Correct 5 ms 25180 KB Output is correct
4 Correct 5 ms 25180 KB Output is correct
5 Correct 6 ms 25180 KB Output is correct
6 Correct 5 ms 25180 KB Output is correct
7 Correct 5 ms 25180 KB Output is correct
8 Correct 6 ms 25180 KB Output is correct
9 Correct 5 ms 25180 KB Output is correct
10 Correct 5 ms 25180 KB Output is correct
11 Correct 5 ms 25180 KB Output is correct
12 Correct 6 ms 25260 KB Output is correct
13 Correct 5 ms 25180 KB Output is correct
14 Correct 5 ms 25256 KB Output is correct
15 Correct 5 ms 25212 KB Output is correct
16 Correct 5 ms 25180 KB Output is correct
17 Correct 6 ms 25180 KB Output is correct
18 Correct 6 ms 25180 KB Output is correct
19 Correct 6 ms 25180 KB Output is correct
20 Correct 5 ms 25180 KB Output is correct
21 Correct 5 ms 25180 KB Output is correct
22 Correct 5 ms 25180 KB Output is correct
23 Correct 6 ms 25268 KB Output is correct
24 Correct 5 ms 25176 KB Output is correct
25 Correct 5 ms 25180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 25180 KB Output is correct
2 Correct 6 ms 25508 KB Output is correct
3 Correct 5 ms 25180 KB Output is correct
4 Correct 5 ms 25180 KB Output is correct
5 Correct 6 ms 25180 KB Output is correct
6 Correct 5 ms 25180 KB Output is correct
7 Correct 5 ms 25180 KB Output is correct
8 Correct 6 ms 25180 KB Output is correct
9 Correct 5 ms 25180 KB Output is correct
10 Correct 5 ms 25180 KB Output is correct
11 Correct 5 ms 25180 KB Output is correct
12 Correct 6 ms 25260 KB Output is correct
13 Correct 5 ms 25180 KB Output is correct
14 Correct 5 ms 25256 KB Output is correct
15 Correct 5 ms 25212 KB Output is correct
16 Correct 5 ms 25180 KB Output is correct
17 Correct 6 ms 25180 KB Output is correct
18 Correct 6 ms 25180 KB Output is correct
19 Correct 6 ms 25180 KB Output is correct
20 Correct 5 ms 25180 KB Output is correct
21 Correct 5 ms 25180 KB Output is correct
22 Correct 5 ms 25180 KB Output is correct
23 Correct 6 ms 25268 KB Output is correct
24 Correct 5 ms 25176 KB Output is correct
25 Correct 5 ms 25180 KB Output is correct
26 Correct 5 ms 25180 KB Output is correct
27 Correct 10 ms 25692 KB Output is correct
28 Correct 12 ms 25900 KB Output is correct
29 Correct 49 ms 28364 KB Output is correct
30 Correct 67 ms 32336 KB Output is correct
31 Correct 127 ms 32288 KB Output is correct
32 Correct 44 ms 32228 KB Output is correct
33 Correct 91 ms 31668 KB Output is correct
34 Correct 87 ms 32336 KB Output is correct
35 Correct 88 ms 31568 KB Output is correct
36 Correct 84 ms 31548 KB Output is correct
37 Correct 46 ms 30752 KB Output is correct
38 Correct 93 ms 31764 KB Output is correct
39 Correct 98 ms 32848 KB Output is correct
40 Correct 46 ms 31776 KB Output is correct
41 Correct 80 ms 32336 KB Output is correct
42 Correct 78 ms 31804 KB Output is correct
43 Correct 95 ms 32848 KB Output is correct
44 Correct 82 ms 31568 KB Output is correct
45 Correct 75 ms 31824 KB Output is correct
46 Correct 74 ms 32592 KB Output is correct
47 Correct 100 ms 32080 KB Output is correct
48 Correct 66 ms 37608 KB Output is correct
49 Correct 103 ms 32316 KB Output is correct
50 Correct 104 ms 33024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 25180 KB Output is correct
2 Correct 6 ms 25508 KB Output is correct
3 Correct 5 ms 25180 KB Output is correct
4 Correct 5 ms 25180 KB Output is correct
5 Correct 6 ms 25180 KB Output is correct
6 Correct 5 ms 25180 KB Output is correct
7 Correct 5 ms 25180 KB Output is correct
8 Correct 6 ms 25180 KB Output is correct
9 Correct 5 ms 25180 KB Output is correct
10 Correct 5 ms 25180 KB Output is correct
11 Correct 5 ms 25180 KB Output is correct
12 Correct 6 ms 25260 KB Output is correct
13 Correct 5 ms 25180 KB Output is correct
14 Correct 5 ms 25256 KB Output is correct
15 Correct 5 ms 25212 KB Output is correct
16 Correct 5 ms 25180 KB Output is correct
17 Correct 6 ms 25180 KB Output is correct
18 Correct 6 ms 25180 KB Output is correct
19 Correct 6 ms 25180 KB Output is correct
20 Correct 5 ms 25180 KB Output is correct
21 Correct 5 ms 25180 KB Output is correct
22 Correct 5 ms 25180 KB Output is correct
23 Correct 6 ms 25268 KB Output is correct
24 Correct 5 ms 25176 KB Output is correct
25 Correct 5 ms 25180 KB Output is correct
26 Correct 5 ms 25180 KB Output is correct
27 Correct 6 ms 25180 KB Output is correct
28 Correct 6 ms 25260 KB Output is correct
29 Correct 6 ms 25180 KB Output is correct
30 Correct 6 ms 25180 KB Output is correct
31 Correct 5 ms 25180 KB Output is correct
32 Correct 5 ms 25180 KB Output is correct
33 Correct 5 ms 25248 KB Output is correct
34 Correct 5 ms 25180 KB Output is correct
35 Correct 5 ms 25180 KB Output is correct
36 Correct 6 ms 25180 KB Output is correct
37 Correct 5 ms 25180 KB Output is correct
38 Correct 6 ms 25180 KB Output is correct
39 Correct 6 ms 25260 KB Output is correct
40 Correct 6 ms 25180 KB Output is correct
41 Correct 5 ms 25200 KB Output is correct
42 Correct 6 ms 25180 KB Output is correct
43 Correct 5 ms 25432 KB Output is correct
44 Correct 5 ms 25180 KB Output is correct
45 Correct 5 ms 25264 KB Output is correct
46 Correct 5 ms 25180 KB Output is correct
47 Correct 5 ms 25180 KB Output is correct
48 Correct 5 ms 25212 KB Output is correct
49 Correct 5 ms 25180 KB Output is correct
50 Correct 5 ms 25180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 25180 KB Output is correct
2 Correct 6 ms 25508 KB Output is correct
3 Correct 5 ms 25180 KB Output is correct
4 Correct 5 ms 25180 KB Output is correct
5 Correct 6 ms 25180 KB Output is correct
6 Correct 5 ms 25180 KB Output is correct
7 Correct 5 ms 25180 KB Output is correct
8 Correct 6 ms 25180 KB Output is correct
9 Correct 5 ms 25180 KB Output is correct
10 Correct 5 ms 25180 KB Output is correct
11 Correct 5 ms 25180 KB Output is correct
12 Correct 6 ms 25260 KB Output is correct
13 Correct 5 ms 25180 KB Output is correct
14 Correct 5 ms 25256 KB Output is correct
15 Correct 5 ms 25212 KB Output is correct
16 Correct 5 ms 25180 KB Output is correct
17 Correct 6 ms 25180 KB Output is correct
18 Correct 6 ms 25180 KB Output is correct
19 Correct 6 ms 25180 KB Output is correct
20 Correct 5 ms 25180 KB Output is correct
21 Correct 5 ms 25180 KB Output is correct
22 Correct 5 ms 25180 KB Output is correct
23 Correct 6 ms 25268 KB Output is correct
24 Correct 5 ms 25176 KB Output is correct
25 Correct 5 ms 25180 KB Output is correct
26 Correct 5 ms 25180 KB Output is correct
27 Correct 10 ms 25692 KB Output is correct
28 Correct 12 ms 25900 KB Output is correct
29 Correct 49 ms 28364 KB Output is correct
30 Correct 67 ms 32336 KB Output is correct
31 Correct 127 ms 32288 KB Output is correct
32 Correct 44 ms 32228 KB Output is correct
33 Correct 91 ms 31668 KB Output is correct
34 Correct 87 ms 32336 KB Output is correct
35 Correct 88 ms 31568 KB Output is correct
36 Correct 84 ms 31548 KB Output is correct
37 Correct 46 ms 30752 KB Output is correct
38 Correct 93 ms 31764 KB Output is correct
39 Correct 98 ms 32848 KB Output is correct
40 Correct 46 ms 31776 KB Output is correct
41 Correct 80 ms 32336 KB Output is correct
42 Correct 78 ms 31804 KB Output is correct
43 Correct 95 ms 32848 KB Output is correct
44 Correct 82 ms 31568 KB Output is correct
45 Correct 75 ms 31824 KB Output is correct
46 Correct 74 ms 32592 KB Output is correct
47 Correct 100 ms 32080 KB Output is correct
48 Correct 66 ms 37608 KB Output is correct
49 Correct 103 ms 32316 KB Output is correct
50 Correct 104 ms 33024 KB Output is correct
51 Correct 5 ms 25180 KB Output is correct
52 Correct 6 ms 25180 KB Output is correct
53 Correct 6 ms 25260 KB Output is correct
54 Correct 6 ms 25180 KB Output is correct
55 Correct 6 ms 25180 KB Output is correct
56 Correct 5 ms 25180 KB Output is correct
57 Correct 5 ms 25180 KB Output is correct
58 Correct 5 ms 25248 KB Output is correct
59 Correct 5 ms 25180 KB Output is correct
60 Correct 5 ms 25180 KB Output is correct
61 Correct 6 ms 25180 KB Output is correct
62 Correct 5 ms 25180 KB Output is correct
63 Correct 6 ms 25180 KB Output is correct
64 Correct 6 ms 25260 KB Output is correct
65 Correct 6 ms 25180 KB Output is correct
66 Correct 5 ms 25200 KB Output is correct
67 Correct 6 ms 25180 KB Output is correct
68 Correct 5 ms 25432 KB Output is correct
69 Correct 5 ms 25180 KB Output is correct
70 Correct 5 ms 25264 KB Output is correct
71 Correct 5 ms 25180 KB Output is correct
72 Correct 5 ms 25180 KB Output is correct
73 Correct 5 ms 25212 KB Output is correct
74 Correct 5 ms 25180 KB Output is correct
75 Correct 5 ms 25180 KB Output is correct
76 Correct 12 ms 25792 KB Output is correct
77 Correct 9 ms 25732 KB Output is correct
78 Correct 21 ms 26868 KB Output is correct
79 Correct 72 ms 29008 KB Output is correct
80 Correct 70 ms 32336 KB Output is correct
81 Correct 46 ms 31512 KB Output is correct
82 Correct 91 ms 31680 KB Output is correct
83 Correct 76 ms 32336 KB Output is correct
84 Correct 81 ms 31568 KB Output is correct
85 Correct 90 ms 32336 KB Output is correct
86 Correct 88 ms 34492 KB Output is correct
87 Correct 85 ms 31824 KB Output is correct
88 Correct 83 ms 31824 KB Output is correct
89 Correct 84 ms 32592 KB Output is correct
90 Correct 46 ms 31520 KB Output is correct
91 Correct 84 ms 32336 KB Output is correct
92 Correct 84 ms 32848 KB Output is correct
93 Correct 84 ms 32848 KB Output is correct
94 Correct 78 ms 32592 KB Output is correct
95 Correct 78 ms 32652 KB Output is correct
96 Correct 74 ms 31656 KB Output is correct
97 Correct 97 ms 32336 KB Output is correct
98 Correct 68 ms 37140 KB Output is correct
99 Correct 110 ms 32456 KB Output is correct
100 Correct 102 ms 32316 KB Output is correct