Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- *
- * problem link: https://onlinejudge.org/index.php?option=onlinejudge&Itemid=8&page=show_problem&category=0&problem=2708&mosmsg=Submission+received+with+ID+27781275
- *
- * */
- #include <bits/stdc++.h>
- using namespace std;
- #define ll long long
- #define endl '\n'
- #define sz(x) int(x.size())
- #define all(x) x.begin(), x.end()
- int main() {
- ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
- int n;
- char s[2000005];
- while (scanf("%d", &n), n) {
- scanf("%s", s);
- int l = -1, r = -1;
- int ans = n;
- for (int i = 0; i < n; i++) {
- if (s[i] == 'Z') {
- ans = 0;
- }
- else {
- if (s[i] == 'R') l = i;
- else if (s[i] == 'D') r = i;
- if (~l && ~r) ans = min(ans, abs(l - r));
- }
- }
- printf("%d\n", ans);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement