結果

問題 No.318 学学学学学
ユーザー yuppe19 😺
提出日時 2015-12-11 20:15:59
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 1,046 ms / 2,000 ms
コード長 810 bytes
コンパイル時間 1,115 ms
コンパイル使用メモリ 79,708 KB
実行使用メモリ 14,340 KB
最終ジャッジ日時 2024-06-22 15:37:33
合計ジャッジ時間 7,867 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 26
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:13:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   13 |   scanf("%d", &n);
      |   ~~~~~^~~~~~~~~~
main.cpp:15:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   15 |     scanf("%d", &p);
      |     ~~~~~^~~~~~~~~~

ソースコード

diff #

// (ΦωΦ)<悪あがき
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <map>
using namespace std;

int n, p, x, y, i;
int b[100005];
unordered_map<int, pair<int, int>> dic;

int main(void) {
  scanf("%d", &n);
  for(i=0; i<n; i++) {
    scanf("%d", &p);
    if(dic.find(p) == dic.end()) {
      x = n, y = -1;
    } else {
      pair<int, int> pr = dic[p];
      x = pr.first, y = pr.second;
    }
    x = min(x, i);
    y = max(y, i);
    dic[p] = make_pair(x, y);
  }
  map<int, pair<int, int>> ordered_dic(dic.begin(), dic.end());
  for(pair<int, pair<int, int>> kv : ordered_dic) {
    for(i=kv.second.first; i<=kv.second.second; i++) {
      b[i] = kv.first;
    }
  }
  printf("%d", b[0]);
  for(i=1; i<n; i++) {
    printf(" %d", b[i]);
  }
  putchar('\n');
  return 0;
}
0