Submission #1561920


Source Code Expand

Copy
// #include {{{
#include <array>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <numeric>
#include <functional>
#include <iterator>
#include <tuple>
#include <utility>
#include <random>
#include <limits>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cstdint>
#include <cassert>
// }}}

using namespace std;

// macros {{{
template<typename T, size_t N>
constexpr size_t NELEMS(T (&)[N]) { return N; }

template<typename InputIt>
void PRINT_RANGE(InputIt first, InputIt last)
{
    for(; first != last; ++first)
        cout << *first << (first==last ? "" : " ");
    cout << "\n";
}

template<typename T>
void PRINT_MATRIX(T mat, size_t nr, size_t nc)
{
    for(size_t r = 0; r < nr; ++r) {
        for(size_t c = 0; c < nc; ++c) {
            cout << mat[r][c] << (c==nc-1 ? "" : " ");
        }
        cout << "\n";
    }
}

#define FOR(i, start, end) for(int i = (start); i < (end); ++i)
#define REP(i, n) FOR(i, 0, n)
// }}}

// types {{{
using ll  = long long;
using ull = unsigned long long;
// }}}

int X;
int K;
int R[100000];

int Q;

void elapse(int& top, int& bot, int dt)
{
    if(top <= dt) {
        bot += top;
        top  = 0;
    }
    else {
        top -= dt;
        bot += dt;
    }
}

int simulate(int t, int a)
{
    int n_flip = 0;
    int top = a;
    int bot = X-a;

    int t_curr = 0;
    REP(i, K) {
        int r = R[i];
        if(r >= t) break;
        elapse(top, bot, r-t_curr);
        swap(top, bot);
        ++n_flip;
        t_curr = r;
#ifdef DEBUG
        cout << "top:" << top << ", bot:" << bot << "\n";
#endif
    }

    elapse(top, bot, t-t_curr);

    int ans = n_flip%2 ? bot : top;
    return ans;
}

int main()
{
    cin >> X;
    cin >> K;
    REP(i, K) {
        cin >> R[i];
    }

    cin >> Q;
    REP(_, Q) {
        int t, a;
        cin >> t >> a;
        int ans = simulate(t, a);
        cout << ans << "\n";
    }

    return 0;
}

Submission Info

Submission Time
Task F - Sandglass
User yumsiim
Language C++14 (GCC 5.4.1)
Score 0
Code Size 2204 Byte
Status
Exec Time 2107 ms
Memory 1280 KB

Judge Result

Set Name Score / Max Score Test Cases
Sample 0 / 0 0_000.txt, 0_001.txt, 0_002.txt
All 0 / 700 0_000.txt, 0_001.txt, 0_002.txt, 1_003.txt, 1_004.txt, 1_005.txt, 1_006.txt, 1_007.txt, 1_008.txt, 1_009.txt, 1_010.txt, 1_011.txt, 1_012.txt, 1_013.txt, 1_014.txt, 1_015.txt, 1_016.txt, 1_017.txt, 1_018.txt, 1_019.txt, 1_020.txt, 1_021.txt, 1_022.txt, 1_023.txt, 1_024.txt, 1_025.txt, 1_026.txt, 1_027.txt, 1_028.txt, 1_029.txt, 1_030.txt, 1_031.txt, 1_032.txt, 1_033.txt, 1_034.txt, 1_035.txt, 1_036.txt, 1_037.txt, 1_038.txt, 1_039.txt, 1_040.txt, 1_041.txt
Case Name Status Exec Time Memory
0_000.txt 1 ms 256 KB
0_001.txt 1 ms 256 KB
0_002.txt 1 ms 256 KB
1_003.txt 2103 ms 768 KB
1_004.txt 2103 ms 768 KB
1_005.txt 2103 ms 768 KB
1_006.txt 2103 ms 768 KB
1_007.txt 2103 ms 768 KB
1_008.txt 2103 ms 768 KB
1_009.txt 2103 ms 768 KB
1_010.txt 2103 ms 768 KB
1_011.txt 2103 ms 768 KB
1_012.txt 2103 ms 768 KB
1_013.txt 2103 ms 768 KB
1_014.txt 2107 ms 768 KB
1_015.txt 2103 ms 896 KB
1_016.txt 2103 ms 896 KB
1_017.txt 2103 ms 768 KB
1_018.txt 2103 ms 896 KB
1_019.txt 2103 ms 896 KB
1_020.txt 2103 ms 896 KB
1_021.txt 2107 ms 768 KB
1_022.txt 2103 ms 1024 KB
1_023.txt 2107 ms 1024 KB
1_024.txt 2103 ms 896 KB
1_025.txt 2103 ms 1024 KB
1_026.txt 2103 ms 1024 KB
1_027.txt 2103 ms 768 KB
1_028.txt 2103 ms 768 KB
1_029.txt 2103 ms 1024 KB
1_030.txt 2103 ms 768 KB
1_031.txt 2103 ms 768 KB
1_032.txt 2103 ms 1152 KB
1_033.txt 252 ms 1024 KB
1_034.txt 330 ms 1024 KB
1_035.txt 2103 ms 1024 KB
1_036.txt 263 ms 1152 KB
1_037.txt 352 ms 1152 KB
1_038.txt 2103 ms 1152 KB
1_039.txt 263 ms 896 KB
1_040.txt 342 ms 1280 KB
1_041.txt 2103 ms 1152 KB