結果
| 問題 |
No.1369 交換門松列・竹
|
| コンテスト | |
| ユーザー |
沙耶花
|
| 提出日時 | 2021-01-29 21:52:34 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 34 ms / 2,000 ms |
| コード長 | 1,622 bytes |
| コンパイル時間 | 1,952 ms |
| コンパイル使用メモリ | 203,444 KB |
| 最終ジャッジ日時 | 2025-01-18 09:10:01 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 33 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:21:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
21 | scanf("%d",&N);
| ~~~~~^~~~~~~~~
main.cpp:25:30: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
25 | scanf("%lld",&A[i]);
| ~~~~~^~~~~~~~~~~~~~
ソースコード
#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 1000000000
bool is_kadomatsu(long long a,long long b,long long c){
if(a==b||b==c||c==a)return false;
if(b>a&&b>c)return true;
if(b<a&&b<c)return true;
return false;
}
int main(){
int T;
cin>>T;
rep(_,T){
int N;
scanf("%d",&N);
vector<long long> A(N);
rep(i,N){
scanf("%lld",&A[i]);
}
vector<int> ind;
int cnt = 0;
rep(i,N-2){
if(is_kadomatsu(A[i],A[i+1],A[i+2]))continue;
rep(j,3){
ind.push_back(i+j);
}
cnt ++;
}
sort(ind.begin(),ind.end());
ind.erase(unique(ind.begin(),ind.end()),ind.end());
// cout<<ind.size()<<endl;
if(ind.size()>10){
printf("No\n");
continue;
}
bool f = false;
rep(i,ind.size()){
int x = ind[i];
rep(j,N){
int y = j;
if(x==y)continue;
int X = 0;
vector<int> t;
for(int k=x-2;k<=x;k++)t.push_back(k);
for(int k=y-2;k<=y;k++)t.push_back(k);
sort(t.begin(),t.end());
t.erase(unique(t.begin(),t.end()),t.end());
rep(l,t.size()){
int k = t[l];
if(k<0)continue;
if(k+2>=N)break;
if(!is_kadomatsu(A[k],A[k+1],A[k+2]))X++;
}
swap(A[x],A[y]);
rep(l,t.size()){
int k = t[l];
if(k<0)continue;
if(k+2>=N)break;
if(!is_kadomatsu(A[k],A[k+1],A[k+2]))X--;
}
swap(A[x],A[y]);
/*
if(x==1&&y==2){
cout<<X<<endl;
cout<<cnt<<endl;
}
*/
if(X==cnt){
f=true;
break;
}
}
if(f)break;
}
if(f)cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}
return 0;
}
沙耶花