# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
137103 | arnold518 | 영역 (JOI16_ho_t4) | C++14 | 1076 ms | 17448 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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> ST;
vector<int> V;
ll ans;
int main()
{
int i, j;
scanf("%d%d%s", &N, &K, S+1);
pii now={0, 0}; ST.insert(now);
V.push_back(0);
for(j=1; j<=K; j++)
{
int a=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++;
ST.insert(now);
}
for(auto it : ST) a+=(ST.count({it.x, it.y}) && ST.count({it.x+1, it.y}) && ST.count({it.x, it.y+1}) && ST.count({it.x+1, it.y+1}));
V.push_back(a);
if(j>50 && 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)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |