結果
| 問題 |
No.1707 Simple Range Reverse Problem
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-10-15 21:41:37 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 3,188 bytes |
| コンパイル時間 | 1,686 ms |
| コンパイル使用メモリ | 180,536 KB |
| 実行使用メモリ | 7,844 KB |
| 最終ジャッジ日時 | 2025-07-13 03:51:00 |
| 合計ジャッジ時間 | 2,374 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 19 |
ソースコード
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline int my_getchar(){
static char buf[1048576];
static int s = 1048576;
static int e = 1048576;
if(s == e && e == 1048576){
e = fread(buf, 1, 1048576, stdin);
s = 0;
}
if(s == e){
return EOF;
}
return buf[s++];
}
inline void rd(int &x){
int k;
int m=0;
x=0;
for(;;){
k = my_getchar();
if(k=='-'){
m=1;
break;
}
if('0'<=k&&k<='9'){
x=k-'0';
break;
}
}
for(;;){
k = my_getchar();
if(k<'0'||k>'9'){
break;
}
x=x*10+k-'0';
}
if(m){
x=-x;
}
}
inline int rd_int(void){
int x;
rd(x);
return x;
}
struct MY_WRITER{
char buf[1048576];
int s;
int e;
MY_WRITER(){
s = 0;
e = 1048576;
}
~MY_WRITER(){
if(s){
fwrite(buf, 1, s, stdout);
}
}
}
;
MY_WRITER MY_WRITER_VAR;
void my_putchar(int a){
if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){
fwrite(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout);
MY_WRITER_VAR.s = 0;
}
MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a;
}
inline void wt_L(char a){
my_putchar(a);
}
inline void wt_L(const char c[]){
int i=0;
for(i=0;c[i]!='\0';i++){
my_putchar(c[i]);
}
}
template<class S, class T> inline S chmin(S &a, T b){
if(a>b){
a=b;
}
return a;
}
template<class S, class T> inline S chmax(S &a, T b){
if(a<b){
a=b;
}
return a;
}
int a[5000+10];
int b[5000+10];
int main(){
int PiIOrLma;
int AuJVIghY = rd_int();
for(PiIOrLma=(0);PiIOrLma<(AuJVIghY);PiIOrLma++){
int i;
int N;
rd(N);
{
int djQeACzd;
for(djQeACzd=(0);djQeACzd<(2*N);djQeACzd++){
rd(a[djQeACzd]);
}
}
for(i=(0);i<(N);i++){
b[i] = b[i+N] = i+1;
}
int lun = 1073709056;
int run = -1;
for(i=(0);i<(2*N);i++){
if(a[i] != b[i]){
chmin(lun, i-1);
chmax(run, i+1);
}
}
if(lun >= 1073709056 || run < 0){
wt_L("Yes");
wt_L('\n');
continue;
}
if(lun < 0 || run >= 2 * N){
wt_L("No");
wt_L('\n');
continue;
}
reverse(b+lun, b + run + 1);
for(i=(0);i<(2*N);i++){
if(a[i] != b[i]){
wt_L("No");
wt_L('\n');
goto FJNsjZ7B;
}
}
wt_L("Yes");
wt_L('\n');
FJNsjZ7B:;
}
return 0;
}
// cLay version 20210405-1
// --- original code ---
// //no-unlocked
// int a[5d3+10];
// int b[5d3+10];
// {
// REP(rd_int()){
// int N;
// rd(N, a(2*N));
// rep(i, N) b[i] = b[i+N] = i+1;
// int lun = int_inf, run = -1;
// rep(i, 2*N){
// if(a[i] != b[i]){
// lun <?= i-1;
// run >?= i+1;
// }
// }
// if(lun >= int_inf || run < 0){
// wt("Yes"); continue;
// }
// //wt(lun, run);
// if(lun < 0 || run >= 2 * N){
// wt("No"); continue;
// }
// reverse(b+lun, b + run + 1);
// rep(i, 2*N){
// if(a[i] != b[i]){
// wt("No");
// break_continue;
// }
// }
// wt("Yes");
// }
// }