QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#268614 | #5305. Oscar is All You Need | Lynkcat# | WA | 5ms | 3612kb | C++23 | 2.9kb | 2023-11-28 19:05:42 | 2023-11-28 19:05:43 |
Judging History
answer
#include<bits/stdc++.h>
#define poly vector<int>
#define IOS ios::sync_with_stdio(false)
#define ll long long
#define mp make_pair
#define mt make_tuple
#define pa pair < int,int >
#define fi first
#define se second
#define inf 1e18
#define mod 998244353
#define sz(x) (int)((x).size())
//#define int ll
//#define N
using namespace std;
const int N=1005;
vector<pa>ans;
int a[N];
int n;
void trans(int x,int y)
{
if (x<=0||y<=0) return;
ans.push_back(mp(x,y));
poly lf=poly(a+1,a+x+1);
poly mid=poly(a+x+1,a+n-y+1);
poly rt=poly(a+n-y+1,a+n+1);
swap(lf,rt);
int t=0;
for (auto u:lf) a[++t]=u;
for (auto u:mid) a[++t]=u;
for (auto u:rt) a[++t]=u;
}
map<poly,pa>Mp;
poly work(poly a,int x,int y)
{
poly lf=poly(a.begin(),a.begin()+x);
poly mid=poly(a.begin()+x,a.end()-y);
poly rt=poly(a.end()-y,a.end());
swap(lf,rt);
int t=0;
for (auto u:lf) a[t++]=u;
for (auto u:mid) a[t++]=u;
for (auto u:rt) a[t++]=u;
return a;
}
void init()
{
poly a;
a=(poly){1,2,3,4};
queue<poly>q;
Mp[a]=mp(0,0);
q.push(a);
while (!q.empty())
{
poly x=q.front();q.pop();
{
poly y=work(x,1,1);
if (!Mp.count(y)) Mp[y]=mp(1,1),q.push(y);
}
{
poly y=work(x,1,2);
if (!Mp.count(y)) Mp[y]=mp(1,2),q.push(y);
}
{
poly y=work(x,2,1);
if (!Mp.count(y)) Mp[y]=mp(2,1),q.push(y);
}
}
}
mt19937_64 rnd(time(0));
void BellaKira()
{
cin>>n;
for (int i=1;i<=n;i++)
{
cin>>a[i];
// a[i]=i;
}
// shuffle(a+1,a+n+1,rnd);
if (n==3)
{
if (a[1]>a[3])
{
cout<<"1\n";
cout<<1<<" "<<1<<'\n';
return;
}
cout<<0<<'\n';
return;
}
for (int i=1;i<n;i++)
{
if (i+2==n)
{
poly now;
now.push_back(1);
for (int j=i;j<=n;j++) now.push_back(a[j]-i+2);
// for (auto u:now) cout<<u<<";";
// cout<<endl;
vector<pa>g;
while (Mp[now]!=mp(0,0))
{
auto [x,y]=Mp[now];
int lf=0,rt=0;
for (int j=1;j<=y;j++)
if (now[j-1]==1) lf+=i-1;
else lf++;
for (int j=sz(now);j>sz(now)-x;j--)
if (now[j-1]==1) rt+=i-1;
else rt++;
trans(lf,rt);
now=work(now,Mp[now].se,Mp[now].fi);
}
break;
}
int pos=0;
for (int j=1;j<=n;j++)
if (a[j]==i) pos=j;
if (pos==i) continue;
if (i==1&&pos==2)
{
trans(1,n-2);
for (int j=1;j<=n;j++)
if (a[j]==i) pos=j;
trans(1,n-pos+1);
continue;
} else
if (i==1)
{
trans(1,n-pos+1);
continue;
}
if (pos!=n)
{
trans(i-1,n-pos);
trans(n-i,i-1);
} else
{
trans(i-1,n-i);
for (int j=1;j<=n;j++)
if (a[j]==i) pos=j;
trans(pos-1,i-1);
}
assert(a[i]==i);
}
cout<<ans.size()<<'\n';
for (auto [x,y]:ans) cout<<x<<" "<<y<<'\n';
for (int i=1;i<=n;i++) assert(a[i]==i);
return;
}
signed main()
{
init();
IOS;
cin.tie(0);
int T=1;
cin>>T;
while (T--)
{
BellaKira();
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3612kb
input:
2 3 1 3 2 5 4 1 2 3 5
output:
0 9 1 3 1 2 1 3 2 1 3 1 1 1 1 3 2 1 2 2
result:
ok OK in maximum 9 operations
Test #2:
score: -100
Wrong Answer
time: 5ms
memory: 3548kb
input:
120 3 1 3 2 3 3 2 1 3 2 3 1 5 1 2 3 4 5 12 11 9 2 8 3 10 6 1 4 7 5 12 36 24 9 7 3 31 15 13 1 4 33 11 29 16 23 2 25 35 21 32 14 6 18 17 26 28 8 27 22 20 36 10 19 34 12 30 5 4 4 2 3 1 5 3 5 2 1 4 4 1 2 4 3 10 5 7 4 9 6 8 1 3 10 2 5 3 1 5 2 4 5 3 5 1 2 4 3 3 1 2 13 3 1 2 11 12 13 8 6 5 4 10 9 7 16 12 8...
output:
0 1 1 1 1 1 1 0 17 1 5 1 5 10 1 2 8 9 2 3 5 8 3 4 6 7 4 5 2 6 5 6 4 5 6 7 2 4 7 8 3 2 8 82 1 5 1 5 10 1 2 8 9 2 3 5 8 3 4 6 7 4 5 2 6 5 6 4 5 6 7 2 4 7 8 3 2 8 1 29 1 28 34 1 2 10 33 2 3 28 32 3 4 6 31 4 5 14 30 5 6 14 29 6 7 10 28 7 8 18 27 8 9 4 26 9 10 16 25 10 11 6 24 11 12 20 23 12 13 13 22 13 ...
result:
wrong answer Integer parameter [name=operations] equals to 82, violates the range [0, 73]