結果
| 問題 | 
                            No.209 Longest Mountain Subsequence
                             | 
                    
| コンテスト | |
| ユーザー | 
                             a
                         | 
                    
| 提出日時 | 2015-05-15 22:46:22 | 
| 言語 | C++11(廃止可能性あり)  (gcc 13.3.0)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 1,024 bytes | 
| コンパイル時間 | 182 ms | 
| コンパイル使用メモリ | 35,712 KB | 
| 実行使用メモリ | 6,912 KB | 
| 最終ジャッジ日時 | 2024-07-06 04:11:09 | 
| 合計ジャッジ時間 | 1,202 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge5 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 5 WA * 1 | 
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:36:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   36 |   scanf("%d",&t);
      |   ~~~~~^~~~~~~~~
main.cpp:38:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   38 |     scanf("%d",&n);
      |     ~~~~~^~~~~~~~~
main.cpp:39:39: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   39 |     for( int i = 0; i < n; i++ ) scanf("%d",a+i);
      |                                  ~~~~~^~~~~~~~~~
            
            ソースコード
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int n;
int a[111];
int dp[111][111][111];
int solve(int s,int t,int u)
{
  if( u == n ) return 0;
  if( dp[s][t][u] >= 0 ) return dp[s][t][u];
  int res = solve(s,t,u+1);
  //printf("%d %d %d\n",a[s],a[t],a[u]);
  if( a[s] < a[t] ) {
    if( a[t] < a[u] && a[t]-a[s] < a[u]-a[t] ) {
      res = max(res,solve(t,u,u+1)+1);
    }
    if( a[t] > a[u] ) {
      res = max(res,solve(t,u,u+1)+1);
    }
  }
  if( a[s] > a[t] ) {
    if( a[t] > a[u] && a[s]-a[t] > a[t]-a[u] ) {
      res = max(res,solve(t,u,u+1)+1);
    }
  }
  return dp[s][t][u] = res;
}
int main(void)
{
  int t;
  scanf("%d",&t);
  while( t-- ) {
    scanf("%d",&n);
    for( int i = 0; i < n; i++ ) scanf("%d",a+i);
    memset(dp,-1,sizeof(dp));
    int res = 1;
    for( int i = 0; i < n; i++ ) {
      for( int j = i+1; j < n; j++ ) {
        if( a[0] != a[1] ) {
          res = max(res,solve(i,j,j+1)+2);
        }
      }
    }
    printf("%d\n",res);
  }
  return 0;
}
            
            
            
        
            
a