結果
| 問題 |
No.284 門松と魔法(2)
|
| コンテスト | |
| ユーザー |
紙ぺーぱー
|
| 提出日時 | 2015-09-08 02:40:40 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,638 bytes |
| コンパイル時間 | 422 ms |
| コンパイル使用メモリ | 47,872 KB |
| 実行使用メモリ | 11,376 KB |
| 最終ジャッジ日時 | 2024-07-19 04:55:56 |
| 合計ジャッジ時間 | 8,048 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 24 TLE * 1 -- * 15 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:12:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
12 | 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",&x);
| ~~~~~^~~~~~~~~
ソースコード
//naive TLE O(N^2)
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
typedef pair<int,int> P;
int n,m,x, h[100050];
P inc[100050][2],dec[100050][2],tmp[2];
int main(){
scanf("%d",&n);
vector<int> hs(n);
for(int i=0;i<n;i++){
scanf("%d",&x);
h[i]=x;
hs[i]=x;
}
hs.emplace_back(-1);hs.emplace_back(1000000000);
sort(hs.begin(),hs.end());
unique(hs.begin(),hs.end());
m=hs.size();
for(int i=0;i<n;i++){
h[i]=lower_bound(hs.begin(),hs.end(),h[i])-hs.begin();
}
for(int i=0;i<m;i++){
inc[i][0]=inc[i][1]=P(-1000000000,-1);
dec[i][0]=dec[i][1]=P(-1000000000,-1);
}
inc[m-1][0]=P(0,0);
dec[0][0]=P(0,m-1);
for(int i=0;i<n;i++){
//dec->inc
const int p=h[i];
for(int j=0;j<p;j++){
for(int k=0;k<2;k++){
const P v=dec[j][k];
if(v.second==p)continue;
if(inc[p][0].first<v.first+1){
inc[p][1]=inc[p][0];
inc[p][0]=P(v.first+1,j);
}else if(inc[p][0].second!=j&&inc[p][1].first<v.first+1){
inc[p][1]=P(v.first+1,j);
}
}
}
//inc->dec
for(int j=p+1;j<m;j++){
for(int k=0;k<2;k++){
const P v=inc[j][k];
if(v.second==p)continue;
if(dec[p][0].first<v.first+1){
dec[p][1]=dec[p][0];
dec[p][0]=P(v.first+1,j);
}else if(dec[p][0].second!=j&&dec[p][1].first<v.first+1){
dec[p][1]=P(v.first+1,j);
}
}
}
}
int ma=0;
for(int i=0;i<m;i++){
for(int j=0;j<2;j++){
ma=max(ma,inc[i][j].first);
ma=max(ma,dec[i][j].first);
}
}
if(ma<=2)ma=0;
printf("%d",ma);
}
紙ぺーぱー