Submission #58939808


Source Code Expand

/*
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx2,fma,bmi,bmi2,sse4.2,popcnt,lzcnt")
*/

#include <bits/stdc++.h>
#define taskname ""
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define i64 long long
#define isz(x) (int)x.size()
using namespace std;

void solve() {
    int n, q;
    cin >> n >> q;

    int l = 0, r = 1, res = 0;
    while (q--) {
        string s;
        int pos;
        cin >> s >> pos;
        --pos;

        if (s[0] == 'L') {
            int ol = l, cnt = 0;
            while (l != pos) {
                if (l == r) {
                    break;
                }
                l = (l + 1) % n;
                ++cnt;
            }
            if (l == r) {
                l = ol, cnt = 0;
                while (l != pos) {
                    l = (l + n - 1) % n;
                    ++cnt;
                }
            }
            res += cnt;
        }
        else {
            int old_r = r, cnt = 0;
            while (r != pos) {
                if (l == r) {
                    break;
                }
                r = (r + 1) % n;
                ++cnt;
            }
            if (l == r) {
                r = old_r, cnt = 0;
                while (r != pos) {
                    r = (r + n - 1) % n;
                    ++cnt;
                }
            }
            res += cnt;
        }
    }
    cout << res << endl;
}

signed main() {

#ifndef CDuongg
    if (fopen(taskname".inp", "r"))
        assert(freopen(taskname".inp", "r", stdin)), assert(freopen(taskname".out", "w", stdout));
#else
    freopen("bai3.inp", "r", stdin);
    freopen("bai3.out", "w", stdout);
    auto start = chrono::high_resolution_clock::now();
#endif

    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1; //cin >> t;
    while(t--) solve();

#ifdef CDuongg
   auto end = chrono::high_resolution_clock::now();
   cout << "\n"; for(int i = 1; i <= 100; ++i) cout << '=';
   cout << "\nExecution time: " << chrono::duration_cast<chrono::milliseconds> (end - start).count() << "[ms]" << endl;
#endif

}

Submission Info

Submission Time
Task B - Hands on Ring (Easy)
User Thanhs
Language C++ 20 (gcc 12.2)
Score 250
Code Size 2197 Byte
Status AC
Exec Time 1 ms
Memory 3608 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 250 / 250
Status
AC × 3
AC × 24
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 3472 KiB
00_sample_01.txt AC 1 ms 3436 KiB
00_sample_02.txt AC 1 ms 3608 KiB
01_random_00.txt AC 1 ms 3380 KiB
01_random_01.txt AC 1 ms 3436 KiB
01_random_02.txt AC 1 ms 3420 KiB
01_random_03.txt AC 1 ms 3332 KiB
01_random_04.txt AC 1 ms 3472 KiB
01_random_05.txt AC 1 ms 3460 KiB
01_random_06.txt AC 1 ms 3396 KiB
01_random_07.txt AC 1 ms 3464 KiB
01_random_08.txt AC 1 ms 3380 KiB
01_random_09.txt AC 1 ms 3476 KiB
01_random_10.txt AC 1 ms 3472 KiB
01_random_11.txt AC 1 ms 3484 KiB
01_random_12.txt AC 1 ms 3476 KiB
01_random_13.txt AC 1 ms 3284 KiB
01_random_14.txt AC 1 ms 3448 KiB
01_random_15.txt AC 1 ms 3416 KiB
02_handmade_00.txt AC 1 ms 3416 KiB
02_handmade_01.txt AC 1 ms 3536 KiB
02_handmade_02.txt AC 1 ms 3480 KiB
02_handmade_03.txt AC 1 ms 3396 KiB
02_handmade_04.txt AC 1 ms 3416 KiB