ABC035B - ドローン
問題:B - ドローン
#include <algorithm> #include <cstdlib> #include <iostream> #include <string> using namespace std; #define REP(i, n) for (int i = 0; i < (n); ++i) int main(void) { string s; int t, x = 0, y = 0, cnt = 0, ans; cin.tie(0); ios::sync_with_stdio(false); cin >> s; cin >> t; REP(i, s.length()) { switch(s[i]) { case 'L': x--; break; case 'R': x++; break; case 'U': y--; break; case 'D': y++; break; case '?': cnt++; break; default: break; } } if (t == 1) { ans = abs(x) + abs(y) + cnt; } else { ans = max((int)s.length() % 2, abs(x) + abs(y) - cnt); } cout << ans << "\n"; return 0; }