結果
| 問題 |
No.365 ジェンガソート
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-04-29 23:21:54 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 694 bytes |
| コンパイル時間 | 617 ms |
| コンパイル使用メモリ | 33,984 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-10-04 18:57:24 |
| 合計ジャッジ時間 | 1,385 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 16 WA * 25 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:37:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
37 | for(i=0,scanf("%d",&n);i<n;i++)scanf("%d",x+i);
| ~~~~~^~~~~~~~~
main.cpp:37:45: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
37 | for(i=0,scanf("%d",&n);i<n;i++)scanf("%d",x+i);
| ~~~~~^~~~~~~~~~
ソースコード
#include <algorithm>
#include <cstdio>
int x[100001],d[100001],c[100001];
int lis(int n){
int i,j,I;
/*
for(i=-1;I=0,++i<n;d[i]=I+1)
for(j=i-1;~j;j--)
if(x[j]<x[i]&&I<d[j])I=d[j];
*/
// http://stackoverflow.com/questions/6129682/longest-increasing-subsequenceonlogn
int sz = 1;
c[1] = x[0];
d[0] = 1;
for(i=0;++i<n;){
if(x[i] < c[1]){
c[1] = x[i];
d[i] = 1;
}else if(x[i] > c[sz]){
c[sz+1] = x[i];
d[i] = sz+1;
sz++;
}else{
int k = std::lower_bound(c,c+sz,x[i])-c;
c[k] = x[i];
d[i] = k;
}
}
for(i=j=0;i<n;i++)
if(d[i]>d[j])j=i;
return d[j];
}
int n,i,T;
int main(){
for(i=0,scanf("%d",&n);i<n;i++)scanf("%d",x+i);
printf("%d\n",n-lis(n));
}