結果
| 問題 |
No.1369 交換門松列・竹
|
| コンテスト | |
| ユーザー |
SSRS
|
| 提出日時 | 2021-01-29 22:10:03 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,198 bytes |
| コンパイル時間 | 1,615 ms |
| コンパイル使用メモリ | 171,136 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-06-27 08:23:13 |
| 合計ジャッジ時間 | 2,892 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | WA * 1 |
| other | AC * 12 WA * 21 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
bool is_kadomatsu(int a, int b, int c){
return (b < a && b < c || b > a && b > c) && a != c;
}
int main(){
int T;
cin >> T;
for (int i = 0; i < T; i++){
int N;
cin >> N;
vector<int> A(N);
for (int j = 0; j < N; j++){
cin >> A[j];
}
vector<int> B(N, 0);
for (int j = 0; j < N - 2; j++){
if (!is_kadomatsu(A[j], A[j + 1], A[j + 2])){
B[j]++;
B[j + 1]++;
B[j + 2]++;
}
}
vector<int> p;
for (int j = 0; j < N; j++){
if (B[j] > 0){
p.push_back(j);
}
}
if (p.size() > 6){
cout << "No" << endl;
} else {
bool ok = false;
int cnt = p.size();
for (int j = 0; j < cnt; j++){
for (int k = j + 1; k < cnt; k++){
swap(A[p[j]], A[p[k]]);
bool ok2 = true;
for (int l = 0; l < N - 2; l++){
if (!is_kadomatsu(A[l], A[l + 1], A[l + 2])){
ok2 = false;
}
}
if (ok2){
ok = true;
}
}
}
if (ok){
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
}
}
}
SSRS