Submission #117171

#TimeUsernameProblemLanguageResultExecution timeMemory
117171onjo0127영역 (JOI16_ho_t4)C++11
38 / 100
1085 ms148224 KiB
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;

set<pii> st;
char S[100009];

int cnt(set<pii> S) {
    int ret = 0;
    for(auto& it: S) {
        int x, y; tie(x, y) = it;
        if(S.find({x+1, y}) != S.end() && S.find({x, y+1}) != S.end() && S.find({x+1, y+1}) != S.end()) ++ret;
    }
    return ret;
}

set<pii> rep(set<pii>& S, int K, int dx, int dy) {
    set<pii> ret;
    for(int i=0; i<K; i++) {
        for(auto& it: S) {
            int x, y; tie(x, y) = it;
            ret.insert({x + dx*i, y + dy*i});
        }
    }
    return ret;
}

int main() {
    int N, K; scanf("%d%d",&N,&K);
    int x = 0, y = 0; st.insert({0, 0});
    for(int i=1; i<=N; i++) {
        scanf(" %c",&S[i]);
        if(S[i] == 'N') ++y;
        if(S[i] == 'S') --y;
        if(S[i] == 'E') ++x;
        if(S[i] == 'W') --x;
        st.insert({x, y});
    }
    if(K == 1) printf("%d", cnt(st));
    else {
        int t = cnt(rep(st, 500, x, y));
        if(K <= 500) printf("%d", cnt(rep(st, K, x, y)));
        else printf("%lld", 1LL * (cnt(rep(st, 501, x, y)) - t) * (K - 500) + t);
    }
    return 0;
}

Compilation message (stderr)

2016_ho_t4.cpp: In function 'int main()':
2016_ho_t4.cpp:29:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     int N, K; scanf("%d%d",&N,&K);
               ~~~~~^~~~~~~~~~~~~~
2016_ho_t4.cpp:32:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf(" %c",&S[i]);
         ~~~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...