QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#432580#4805. Grammy SortingN_z_WA 1ms3548kbC++145.3kb2024-06-07 12:44:352024-06-07 12:44:35

Judging History

你现在查看的是最新测评结果

  • [2024-06-07 12:44:35]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3548kb
  • [2024-06-07 12:44:35]
  • 提交

answer

#if defined(LOCAL) or not defined(LUOGU)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast,unroll-loops")
#endif
#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include"dbg.h"
#else
#define dbg(...) (__VA_ARGS__)
#endif
namespace Fread{const int SIZE=1<<16;char buf[SIZE],*S,*T;inline char getchar(){if(S==T){T=(S=buf)+fread(buf,1,SIZE,stdin);if(S==T)return'\n';}return *S++;}}namespace Fwrite{const int SIZE=1<<16;char buf[SIZE],*S=buf,*T=buf+SIZE;inline void flush(){fwrite(buf,1,S-buf,stdout);S=buf;}inline void putchar(char c){*S++=c;if(S==T)flush();}struct NTR{~NTR(){flush();}}ztr;}
#define getchar Fread::getchar
#define putchar Fwrite::putchar
#define Setprecision 10
#define between '\n'
#define __int128 long long
template<typename T>struct is_char{static constexpr bool value=(std::is_same<T,char>::value||std::is_same<T,signed char>::value||std::is_same<T,unsigned char>::value);};template<typename T>struct is_integral_ex{static constexpr bool value=(std::is_integral<T>::value||std::is_same<T,__int128>::value)&&!is_char<T>::value;};template<typename T>struct is_floating_point_ex{static constexpr bool value=std::is_floating_point<T>::value||std::is_same<T,__float128>::value;};namespace Fastio{struct Reader{template<typename T>typename std::enable_if_t<std::is_class<T>::value,Reader&>operator>>(T&x){for(auto &y:x)*this>>y;return *this;}template<typename T>typename std::enable_if_t<is_integral_ex<T>::value,Reader&>operator>>(T&x){char c=getchar();short f=1;while(c<'0'||c>'9'){if(c=='-')f*=-1;c=getchar();}x=0;while(c>='0'&&c<='9'){x=(x<<1)+(x<<3)+(c^48);c=getchar();}x*=f;return *this;}template<typename T>typename std::enable_if_t<is_floating_point_ex<T>::value,Reader&>operator>>(T&x){char c=getchar();short f=1,s=0;x=0;T t=0;while((c<'0'||c>'9')&&c!='.'){if(c=='-')f*=-1;c=getchar();}while(c>='0'&&c<='9'&&c!='.')x=x*10+(c^48),c=getchar();if(c=='.')c=getchar();else return x*=f,*this;while(c>='0'&&c<='9')t=t*10+(c^48),s++,c=getchar();while(s--)t/=10.0;x=(x+t)*f;return*this;}template<typename T>typename std::enable_if_t<is_char<T>::value,Reader&>operator>>(T&c){c=getchar();while(c=='\n'||c==' '||c=='\r')c=getchar();return *this;}Reader&operator>>(char*str){int len=0;char c=getchar();while(c=='\n'||c==' '||c=='\r')c=getchar();while(c!='\n'&&c!=' '&&c!='\r')str[len++]=c,c=getchar();str[len]='\0';return*this;}Reader&operator>>(std::string&str){str.clear();char c=getchar();while(c=='\n'||c==' '||c=='\r')c=getchar();while(c!='\n'&&c!=' '&&c!='\r')str.push_back(c),c=getchar();return*this;}Reader(){}}cin;const char endl='\n';struct Writer{typedef __int128 mxdouble;template<typename T>typename std::enable_if_t<std::is_class<T>::value,Writer&>operator<<(T x){for(auto &y:x)*this<<y<<between;*this<<'\n';return *this;}template<typename T>typename std::enable_if_t<is_integral_ex<T>::value,Writer&>operator<<(T x){if(x==0)return putchar('0'),*this;if(x<0)putchar('-'),x=-x;static int sta[45];int top=0;while(x)sta[++top]=x%10,x/=10;while(top)putchar(sta[top]+'0'),--top;return*this;}template<typename T>typename std::enable_if_t<is_floating_point_ex<T>::value,Writer&>operator<<(T x){if(x<0)putchar('-'),x=-x;x+=pow(10,-Setprecision)/2;mxdouble _=x;x-=(T)_;static int sta[45];int top=0;while(_)sta[++top]=_%10,_/=10;if(!top)putchar('0');while(top)putchar(sta[top]+'0'),--top;putchar('.');for(int i=0;i<Setprecision;i++)x*=10;_=x;while(_)sta[++top]=_%10,_/=10;for(int i=0;i<Setprecision-top;i++)putchar('0');while(top)putchar(sta[top]+'0'),--top;return*this;}template<typename T>typename std::enable_if_t<is_char<T>::value,Writer&>operator<<(T c){putchar(c);return*this;}Writer&operator<<(char*str){int cur=0;while(str[cur])putchar(str[cur++]);return *this;}Writer&operator<<(const char*str){int cur=0;while(str[cur])putchar(str[cur++]);return*this;}Writer&operator<<(std::string str){int st=0,ed=str.size();while(st<ed)putchar(str[st++]);return*this;}Writer(){}}cout;}
#define cin Fastio::cin
#define cout Fastio::cout
#define endl Fastio::endl

void solve();
main()
{
#if not defined(LOCAL) and not defined(ONLINE_JUDGE)
    string A="sorting";freopen((A+".in").c_str(),"r",stdin);freopen((A+".out").c_str(),"w",stdout);
#endif
    int t=1;
    // cin>>t;
    while(t--)solve();
}
void solve()
{
	int n,m,s,t;
	cin>>n>>m>>s>>t;
	vector<int>a(n+1);
	for(int x=1;x<=n;x++)
	cin>>a[x];
	vector<vector<int>>e(n+1,vector<int>(n+1));
	bool bo=1;
	for(int x=1;x<=m;x++)
	{
		int u,v;
		cin>>u>>v;
		if(u>v)swap(u,v);
		e[u][v]=e[v][u]=1;
		bo&=(u==x&&v==x+1);
	}
	vector<int>match(n+1);
	for(int x=1;x<=n;x++)
	match[x]=x;
	if(n==3)
	{
		int _=1^2^3^s^t;
		if(!e[s][_]||!e[_][t]){cout<<-1<<endl;return;}
		if(s==1&&t==2)swap(match[2],match[3]),swap(a[2],a[3]),t=3;
		if(s==2&&t==1)swap(match[2],match[3]),swap(a[2],a[3]),s=3;
		if(s==3&&t==2)swap(match[2],match[1]),swap(a[2],a[1]),t=1;
		if(s==2&&t==3)swap(match[2],match[1]),swap(a[2],a[1]),s=1;
		bo=1;
	}
	if(bo)
	{
		bool fl=0;
		if(s==n)swap(s,t),reverse(a.begin()+1,a.begin()+1+n),reverse(match.begin()+1,match.begin()+1+n);
		if(s!=1||t!=n){cout<<-1<<endl;return;}
		cout<<n-1<<endl;
		for(int x=n;x>=2;x--)
		{
			int pl=lower_bound(a.begin()+1+x,a.begin()+1+n,a[1])-a.begin()-1;
			if(a[1]<a[pl])pl--;
			cout<<pl<<' ';
			for(int x=1;x<=pl;x++)
			cout<<match[x]<<' ';cout<<endl;
			for(int x=1;x<pl;x++)
			swap(a[x],a[x+1]);
//			dbg(a);
		}
		return;
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3548kb

input:

5 6 1 2
1 2 3 4 5
1 3
2 3
1 4
2 4
1 5
3 5

output:


result:

wrong output format Unexpected end of file - int32 expected