結果

問題 No.1537 私の代わりに仕事やっといてください。
ユーザー tnakao0123tnakao0123
提出日時 2021-06-08 13:40:27
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 65 ms / 2,000 ms
コード長 1,287 bytes
コンパイル時間 815 ms
コンパイル使用メモリ 94,420 KB
実行使用メモリ 6,724 KB
最終ジャッジ日時 2023-08-17 19:02:49
合計ジャッジ時間 1,777 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 65 ms
6,724 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,384 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 3 ms
4,380 KB
testcase_10 AC 6 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 1537.cc:  No.1537 私の代わりに仕事やっといてください。 - yukicoder
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 200000;

/* typedef */

typedef pair<int,int> pii;

/* global variables */

int as[MAX_N], q[MAX_N * 2];
pii ps[MAX_N];

/* subroutines */

/* main */

int main() {
  int n;
  scanf("%d", &n);

  for (int i = 0; i < n; i++)
    scanf("%d", as + i), ps[i] = pii(as[i], i);
  sort(ps, ps + n);

  int qh = n, qt = n;
  q[qh] = ps[n - 1].second;

  int st = -1;
  for (int i = n - 2; i >= 0; i--) {
    int j = ps[i].second;
    if (as[q[qh]] >= as[q[qt]]) {
      q[--qh] = j;
      if (j == 0) st = qh;
    }
    else {
      q[++qt] = j;
      if (j == 0) st = qt;
    }
  }
  //for (int i = qh; i <= qt; i++) printf("%d ", q[i]); putchar('\n');
  //printf("st=%d\n", st);

  for (int i = 0, j = st; i < n; i++) {
    printf("%d ", q[j] + 1);
    if (++j > qt) j = qh;
  }
  puts("1");
  return 0;
}
0