Submission #137114

#TimeUsernameProblemLanguageResultExecution timeMemory
137114arnold518영역 (JOI16_ho_t4)C++14
38 / 100
576 ms20684 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int MAXN = 1e5; #define x first #define y second int N, K; char S[MAXN+10]; set<pii> S1, S2; vector<ll> V; ll ans; int main() { int i, j; scanf("%d%d%s", &N, &K, S+1); pii now={0, 0}; S1.insert(now); V.push_back(0); for(j=1; j<=K; j++) { set<pii> S3; if(j==1) S3.insert({0, 0}); for(i=1; i<=N; i++) { if(S[i]=='N') now.y++; else if(S[i]=='S') now.y--; else if(S[i]=='W') now.x--; else now.x++; if(!S1.count(now)) S1.insert(now), S3.insert(now); } for(auto it : S3) { if(S1.count({it.x, it.y}) && S1.count({it.x+1, it.y}) && S1.count({it.x, it.y+1}) && S1.count({it.x+1, it.y+1})) S2.insert({it.x, it.y}); if(S1.count({it.x, it.y}) && S1.count({it.x+1, it.y}) && S1.count({it.x, it.y-1}) && S1.count({it.x+1, it.y-1})) S2.insert({it.x, it.y-1}); if(S1.count({it.x, it.y}) && S1.count({it.x-1, it.y}) && S1.count({it.x, it.y+1}) && S1.count({it.x-1, it.y+1})) S2.insert({it.x-1, it.y}); if(S1.count({it.x, it.y}) && S1.count({it.x-1, it.y}) && S1.count({it.x, it.y-1}) && S1.count({it.x-1, it.y-1})) S2.insert({it.x-1, it.y-1}); } //printf("%d\n", S2.size()); V.push_back((ll)S2.size()); if(j>40 && V[j]-V[j-1]==V[j-1]-V[j-2]) { printf("%lld", V[j]+(ll)(K-j)*(V[j]-V[j-1])); return 0; } } printf("%lld", V[K]); }

Compilation message (stderr)

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