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;
using pii = pair<int,int>;
#define ll long long
set<pii> s;
int dx[512], dy[512];
int main() {
cin.tie(0)->sync_with_stdio(0);
int n, k; cin >> n >> k;
string A; cin >> A;
dx['S']--, dx['N']++, dy['E']++, dy['W']--;
int x = 0, y = 0;
s.insert({x,y});
ll dc = 0,ct = 0, pc = 0;
for(;k;){
k--;
for(char i : A) {
x += dx[i], y += dy[i];
s.insert({x,y});
}
ll c = 0;
for(auto i : s) if(
s.find({i.first+1,i.second}) != s.end() &&
s.find({i.first,i.second+1}) != s.end() &&
s.find({i.first+1,i.second+1}) != s.end()
) c++;
if(c-pc==dc) ct++;
else dc = c-pc, ct = 1;
pc = c;
if(ct>=10) break;
}
cout << pc+dc*k;
}
Compilation message (stderr)
2016_ho_t4.cpp: In function 'int main()':
2016_ho_t4.cpp:18:21: warning: array subscript has type 'char' [-Wchar-subscripts]
18 | x += dx[i], y += dy[i];
| ^
2016_ho_t4.cpp:18:33: warning: array subscript has type 'char' [-Wchar-subscripts]
18 | x += dx[i], y += dy[i];
| ^
# | 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... |