提出 #35616036


ソースコード 拡げる

#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

#define mp make_pair
#define pb push_back
#define ll long long

const int limit = 2000000;
const int maxN = 300011;
const int base = 2000000;

struct Crazy {
  int l, r; 
  vector<int> data;
  bool rev;

  Crazy() {}

  Crazy(int low, int high) {
    l = 0; 
    r = high - low;
    rev = false;
    data.resize(limit);

    for (int i = low; i <= high; i++)
      data[i - low] = i + base;
  }

  int& operator[](int id) {
    if (!rev)
      return data[(l + id) % limit];
    else
      return data[(r - id + limit) % limit];
  }

  void extend_raw(int extra) {
    if (!rev)
      l = (l - extra + limit) % limit;
    else
      r = (r + extra) % limit;
  }

  void revert() {
    rev = !rev;
  }

  void extend(int extra, int step) {
    Crazy& me = *this;

    extend_raw(extra + 1);
    me[extra] = -step;
    for (int i = 1; i <= extra; i++) {
      me[extra - i] = me[extra + i];
      if (me[extra - i] > 0)
        me[extra - i] = 2 * base - me[extra - i];
    }
  }
};

int n, m;
int x[maxN];
int d[maxN];
Crazy crazy;

void solve(int step, int l, int r) {
  if (l > r) {
    crazy = Crazy(1, 0);
    return;
  }

  if (step == m + 1) {
    crazy = Crazy(l, r);
    return;
  }
  const int dd = d[step];
  l -= dd; r -= dd;

  if (l > 0) {
    solve(step + 1, l, r);
  } else if (r < 0) {
    solve(step + 1, -r, -l);
    crazy.revert();
  } else if (-l <= r) {
    solve(step + 1, 1, r);
    crazy.extend(-l, step);
  } else {
    solve(step + 1, 1, -l);
    crazy.extend(r, step);
    crazy.revert();
  }
}

int main()
{
  cin >> n >> m;

  for (int i = 1; i <= n; i++)
    cin >> x[i];

  for (int i = 1; i <= m; i++)
    cin >> d[i];

  solve(1, 1, 1000000);
  
  for (int i = 1; i <= n; i++) {
    int val = crazy[x[i] - 1];

    if (val < 0)
      cout << "Yes " << -val << '\n';
    else
      cout << "No " << (crazy.rev ? base - val : val - base) << '\n';
  }


  return 0;
}

提出情報

提出日時
問題 D - Simultaneous Sugoroku
ユーザ atatomir
言語 C++ (Clang 10.0.0)
得点 700
コード長 2155 Byte
結果 AC
実行時間 404 ms
メモリ 37164 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 700 / 700
結果
AC × 1
AC × 33
セット名 テストケース
Sample 01_sample_01.txt
All 01_sample_01.txt, 02_small_01.txt, 02_small_02.txt, 02_small_03.txt, 02_small_04.txt, 02_small_05.txt, 02_small_06.txt, 02_small_07.txt, 02_small_08.txt, 02_small_09.txt, 02_small_10.txt, 03_rand_01.txt, 03_rand_02.txt, 03_rand_03.txt, 03_rand_04.txt, 03_rand_05.txt, 03_rand_06.txt, 03_rand_07.txt, 03_rand_08.txt, 03_rand_09.txt, 03_rand_10.txt, 04_small_d_01.txt, 04_small_d_02.txt, 04_small_d_03.txt, 04_small_d_04.txt, 04_small_d_05.txt, 05_large_d_01.txt, 05_large_d_02.txt, 05_large_d_03.txt, 05_large_d_04.txt, 05_large_d_05.txt, 06_handmade_01.txt, 06_handmade_02.txt
ケース名 結果 実行時間 メモリ
01_sample_01.txt AC 15 ms 10708 KiB
02_small_01.txt AC 18 ms 10716 KiB
02_small_02.txt AC 17 ms 10680 KiB
02_small_03.txt AC 16 ms 10616 KiB
02_small_04.txt AC 17 ms 10648 KiB
02_small_05.txt AC 15 ms 10660 KiB
02_small_06.txt AC 17 ms 10500 KiB
02_small_07.txt AC 15 ms 10668 KiB
02_small_08.txt AC 15 ms 10544 KiB
02_small_09.txt AC 16 ms 10648 KiB
02_small_10.txt AC 15 ms 10716 KiB
03_rand_01.txt AC 402 ms 29460 KiB
03_rand_02.txt AC 401 ms 29432 KiB
03_rand_03.txt AC 402 ms 29452 KiB
03_rand_04.txt AC 402 ms 29368 KiB
03_rand_05.txt AC 403 ms 29444 KiB
03_rand_06.txt AC 402 ms 29312 KiB
03_rand_07.txt AC 399 ms 29188 KiB
03_rand_08.txt AC 404 ms 29460 KiB
03_rand_09.txt AC 400 ms 29452 KiB
03_rand_10.txt AC 402 ms 29452 KiB
04_small_d_01.txt AC 314 ms 15080 KiB
04_small_d_02.txt AC 323 ms 14988 KiB
04_small_d_03.txt AC 319 ms 14996 KiB
04_small_d_04.txt AC 321 ms 15052 KiB
04_small_d_05.txt AC 323 ms 15076 KiB
05_large_d_01.txt AC 379 ms 37084 KiB
05_large_d_02.txt AC 382 ms 37120 KiB
05_large_d_03.txt AC 380 ms 37008 KiB
05_large_d_04.txt AC 382 ms 37124 KiB
05_large_d_05.txt AC 383 ms 37008 KiB
06_handmade_01.txt AC 315 ms 37164 KiB
06_handmade_02.txt AC 381 ms 37108 KiB