AtCoder Beginner Contest 013

Submission #3978851

Source codeソースコード

#include <iostream>
#include <vector>
using namespace std;

int main () {
  int n, k, d;
  cin >> n >> k >> d;
  int a[k];
  for (int i = 0; i < k; i++) {
    cin >> a[i];  
  } 
  int dis[n + 1];
  for (int i = 0; i <= n; i++) {
    dis[i] = i;  
  }
  for (int i = 0; i < k; i++) {
    swap(dis[a[i]], dis[a[i] + 1]);  
  }
  int dis2[n + 1], ans[n + 1];
  dis2[0] = 0;
  ans[0] = 0;
  for (int i = 1; i <= n; i++) {
    dis2[dis[i]] = i;
    ans[i] = 0;
  }
  for (int i = 1; i <= n; i++) {
    if (ans[i] == 0) {
      vector<int> box;
      box.push_back(i);
      int now = dis2[i];
      while (now != box[0]) {
        box.push_back(now);
        now = dis2[now];  
      }
      int dd = d % box.size();
      if (box.size() == 1) {
        ans[now] = now;    
      }
      else {
        for (int j = 0; j < box.size(); j++) {
          // ans[box[j]]について考えている
          now = box[j];
          if (j + dd < box.size()) {
            ans[now] = box[j + dd];  
          }      
          else {
            int l = j + dd - box.size();
            ans[now] = box[l];  
          }
        }
      }
    }  
  }
  for (int i = 1; i <= n; i++) {
    cout << ans[i] << endl;  
  }
}

Submission

Task問題 D - 阿弥陀
User nameユーザ名 ijm
Created time投稿日時
Language言語 C++14 (GCC 5.4.1)
Status状態 AC
Score得点 100
Source lengthソースコード長 1264 Byte
File nameファイル名
Exec time実行時間 210 ms
Memory usageメモリ使用量 2816 KB

Test case

Set

Set name Score得点 / Max score Cases
Subtask1 10 / 10 sample_1.txt,01_i.txt,01_random01.txt,01_random02.txt,01_random03.txt,01_random04.txt,01_random05.txt,01_random06.txt,01_random07.txt
Subtask2 20 / 20 sample_1.txt,sample_2.txt,sample_3.txt,02_i.txt,02_p.txt,02_random01.txt,02_random02.txt,02_random03.txt,02_random04.txt,02_random05.txt,02_random06.txt,02_random07.txt,02_random08.txt,02_rp01.txt,02_rp02.txt,02_rp03.txt,02_rp04.txt,02_rp05.txt
Subtask3 20 / 20 sample_1.txt,sample_2.txt,03_i.txt,03_random01.txt,03_random02.txt,03_random03.txt,03_random04.txt,03_random05.txt,03_random06.txt,03_random07.txt,03_random08.txt,03_random09.txt,03_random10.txt,03_random11.txt,03_random12.txt,03_random13.txt,03_random14.txt,03_random15.txt
Subtask4 50 / 50 sample_1.txt,sample_2.txt,sample_3.txt,04_i.txt,04_p1.txt,04_p2.txt,04_random01.txt,04_random02.txt,04_random03.txt,04_random04.txt,04_random05.txt,04_random06.txt,04_random07.txt,04_random08.txt,04_random09.txt,04_random10.txt,04_random11.txt,04_random12.txt,04_random13.txt,04_rp01.txt,04_rp02.txt,04_rp03.txt,04_rp04.txt,04_rp05.txt,04_rp06.txt,04_rp07.txt,04_rp08.txt,04_rp09.txt,04_rp10.txt

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
01_i.txt AC 208 ms 2816 KB
01_random01.txt AC 1 ms 256 KB
01_random02.txt AC 1 ms 256 KB
01_random03.txt AC 1 ms 256 KB
01_random04.txt AC 8 ms 384 KB
01_random05.txt AC 163 ms 2048 KB
01_random06.txt AC 197 ms 2560 KB
01_random07.txt AC 210 ms 2816 KB
02_i.txt AC 3 ms 256 KB
02_p.txt AC 3 ms 256 KB
02_random01.txt AC 1 ms 256 KB
02_random02.txt AC 1 ms 256 KB
02_random03.txt AC 3 ms 256 KB
02_random04.txt AC 3 ms 256 KB
02_random05.txt AC 7 ms 384 KB
02_random06.txt AC 24 ms 640 KB
02_random07.txt AC 45 ms 1024 KB
02_random08.txt AC 45 ms 1024 KB
02_rp01.txt AC 3 ms 256 KB
02_rp02.txt AC 3 ms 256 KB
02_rp03.txt AC 3 ms 256 KB
02_rp04.txt AC 3 ms 256 KB
02_rp05.txt AC 3 ms 256 KB
03_i.txt AC 1 ms 256 KB
03_random01.txt AC 4 ms 256 KB
03_random02.txt AC 31 ms 1024 KB
03_random03.txt AC 26 ms 896 KB
03_random04.txt AC 25 ms 896 KB
03_random05.txt AC 6 ms 384 KB
03_random06.txt AC 5 ms 384 KB
03_random07.txt AC 8 ms 384 KB
03_random08.txt AC 2 ms 256 KB
03_random09.txt AC 10 ms 512 KB
03_random10.txt AC 17 ms 640 KB
03_random11.txt AC 29 ms 896 KB
03_random12.txt AC 30 ms 1024 KB
03_random13.txt AC 24 ms 768 KB
03_random14.txt AC 19 ms 640 KB
03_random15.txt AC 8 ms 384 KB
04_i.txt AC 208 ms 2816 KB
04_p1.txt AC 183 ms 2432 KB
04_p2.txt AC 142 ms 1920 KB
04_random01.txt AC 114 ms 1664 KB
04_random02.txt AC 82 ms 1152 KB
04_random03.txt AC 42 ms 768 KB
04_random04.txt AC 59 ms 1152 KB
04_random05.txt AC 60 ms 1024 KB
04_random06.txt AC 117 ms 1664 KB
04_random07.txt AC 107 ms 1664 KB
04_random08.txt AC 91 ms 1408 KB
04_random09.txt AC 78 ms 1280 KB
04_random10.txt AC 110 ms 1536 KB
04_random11.txt AC 209 ms 2816 KB
04_random12.txt AC 209 ms 2816 KB
04_random13.txt AC 210 ms 2816 KB
04_rp01.txt AC 179 ms 2452 KB
04_rp02.txt AC 179 ms 2520 KB
04_rp03.txt AC 179 ms 2464 KB
04_rp04.txt AC 179 ms 2600 KB
04_rp05.txt AC 186 ms 2552 KB
04_rp06.txt AC 179 ms 2536 KB
04_rp07.txt AC 180 ms 2512 KB
04_rp08.txt AC 179 ms 2608 KB
04_rp09.txt AC 179 ms 2512 KB
04_rp10.txt AC 178 ms 2600 KB
sample_1.txt AC 1 ms 256 KB
sample_2.txt AC 1 ms 256 KB
sample_3.txt AC 1 ms 256 KB