Submission #58938616
Source Code Expand
/// Msaa el 5ra
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define F first
#define S second
#define f(i, a, b) for (int i = a; i < b; i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define sz(x) (int)(x).size()
#define mp(x, y) make_pair(x, y)
#define popCnt(x) (__builtin_popcountll(x))
//#define int ll
using ll = long long;
using ii = pair<int, int>;
using ull = unsigned long long;
const int N = 2e5 + 5, A = 26, LG = 19, MOD = (119 << 23) +1, MOD2 = 1e9 + 7;
const long double PI = acos(-1);
const long double EPS = 1e-7;
const ll MAX = 1e15;
void doWork() {
int L = 0, R = 1;
int n, q;
cin >> n >> q;
int ans = 0;
while(q--) {
char c;
int x;
cin >> c >> x;
--x;
if(c == 'L') {
int cnt1 = 0, cnt2 = 0;
int i = L, j = L;
for(i = L; i != x && i != R; i = (i + 1) % n) cnt1 += 1;
for(j = L; j != x && j != R; j = (j + n - 1) % n) cnt2 += 1;
int val = INT_MAX;
if(i!=R) val = min(val, cnt1);
if(j!=R) val = min(val, cnt2);
ans += val;
L = x;
} else {
int cnt1 = 0, cnt2 = 0;
int i = R, j = R;
for(i = R; i != x && i != L; i = (i + 1) % n) cnt1 += 1;
for(j = R; j != x && j != L; j = (j + n - 1) % n) cnt2 += 1;
int val = INT_MAX;
if(i!=L) val = min(val, cnt1);
if(j!=L) val = min(val, cnt2);
ans += val;
R = x;
}
}
cout << ans << "\n";
}
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int t = 1;
// cin >> t;
while (t--) {
doWork();
}
}
Submission Info
| Submission Time | |
|---|---|
| Task | B - Hands on Ring (Easy) |
| User | triplem5ds |
| Language | C++ 20 (gcc 12.2) |
| Score | 250 |
| Code Size | 1809 Byte |
| Status | AC |
| Exec Time | 1 ms |
| Memory | 3600 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 250 / 250 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt |
| All | 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 02_handmade_00.txt, 02_handmade_01.txt, 02_handmade_02.txt, 02_handmade_03.txt, 02_handmade_04.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 00_sample_00.txt | AC | 1 ms | 3600 KiB |
| 00_sample_01.txt | AC | 1 ms | 3464 KiB |
| 00_sample_02.txt | AC | 1 ms | 3524 KiB |
| 01_random_00.txt | AC | 1 ms | 3428 KiB |
| 01_random_01.txt | AC | 1 ms | 3448 KiB |
| 01_random_02.txt | AC | 1 ms | 3392 KiB |
| 01_random_03.txt | AC | 1 ms | 3328 KiB |
| 01_random_04.txt | AC | 1 ms | 3464 KiB |
| 01_random_05.txt | AC | 1 ms | 3420 KiB |
| 01_random_06.txt | AC | 1 ms | 3384 KiB |
| 01_random_07.txt | AC | 1 ms | 3412 KiB |
| 01_random_08.txt | AC | 1 ms | 3340 KiB |
| 01_random_09.txt | AC | 1 ms | 3452 KiB |
| 01_random_10.txt | AC | 1 ms | 3472 KiB |
| 01_random_11.txt | AC | 1 ms | 3416 KiB |
| 01_random_12.txt | AC | 1 ms | 3468 KiB |
| 01_random_13.txt | AC | 1 ms | 3412 KiB |
| 01_random_14.txt | AC | 1 ms | 3468 KiB |
| 01_random_15.txt | AC | 1 ms | 3400 KiB |
| 02_handmade_00.txt | AC | 1 ms | 3460 KiB |
| 02_handmade_01.txt | AC | 1 ms | 3448 KiB |
| 02_handmade_02.txt | AC | 1 ms | 3396 KiB |
| 02_handmade_03.txt | AC | 1 ms | 3468 KiB |
| 02_handmade_04.txt | AC | 1 ms | 3468 KiB |