結果
問題 |
No.8009 異なる数字の最大の範囲(勉強会用)
|
ユーザー |
|
提出日時 | 2020-05-05 05:39:47 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 34 ms / 5,000 ms |
コード長 | 608 bytes |
コンパイル時間 | 2,058 ms |
コンパイル使用メモリ | 193,180 KB |
最終ジャッジ日時 | 2025-01-10 06:41:17 |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 22 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:8:21: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 8 | int n; scanf("%d",&n); | ~~~~~^~~~~~~~~ main.cpp:10:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 10 | rep(i,n) scanf("%d",&a[i]); | ~~~~~^~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<(n);i++) using namespace std; int main(){ int n; scanf("%d",&n); vector<int> a(n); rep(i,n) scanf("%d",&a[i]); int lo=0,hi=n+1; while(hi-lo>1){ int mi=(lo+hi)/2; bool ok=false; int dup=0; static int cnt[1000001]; rep(i,mi){ cnt[a[i]]++; if(cnt[a[i]]==2) dup++; } for(int i=mi;i<=n;i++){ if(dup==0) ok=true; if(i<n){ cnt[a[i]]++; if(cnt[a[i]]==2) dup++; cnt[a[i-mi]]--; if(cnt[a[i-mi]]==1) dup--; } } if(ok) lo=mi; else hi=mi; rep(i,n) cnt[a[i]]=0; } printf("%d\n",lo); return 0; }