結果
問題 |
No.2779 Don't make Pair
|
ユーザー |
![]() |
提出日時 | 2024-06-08 13:20:27 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 116 ms / 2,000 ms |
コード長 | 834 bytes |
コンパイル時間 | 646 ms |
コンパイル使用メモリ | 64,504 KB |
最終ジャッジ日時 | 2025-02-21 20:55:10 |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 24 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:32:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 32 | scanf("%d", &n); | ~~~~~^~~~~~~~~~ main.cpp:33:36: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 33 | for (int i = 0; i < n; i++) scanf("%d", as + i); | ~~~~~^~~~~~~~~~~~~~
ソースコード
/* -*- coding: utf-8 -*- * * 2779.cc: No.2779 Don't make Pair - yukicoder */ #include<cstdio> #include<vector> #include<map> #include<algorithm> using namespace std; /* constant */ const int MAX_N = 200000; /* typedef */ typedef vector<int> vi; typedef map<int,vi> mivi; /* global variables */ int as[MAX_N]; /* subroutines */ /* main */ int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d", as + i); mivi avs; for (int i = 0; i < n; i++) avs[as[i]].push_back(i); int l = 0, r = n - 1; for (auto &[a, v]: avs) { if (v.size() > 2) { puts("0\n"); return 0; } if (v.size() == 2) { l = max(l, v[0]); r = min(r, v[1]); } } int k = max(0, r - l); printf("%d\n", k); for (int i = l; i < r; i++) printf("%d ", i + 1); putchar('\n'); return 0; }