QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#59963#1845. PermuteExplodingKonjacWA 2ms3700kbC++175.7kb2022-11-02 10:44:452022-11-02 10:44:46

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-11-02 10:44:46]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3700kb
  • [2022-11-02 10:44:45]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
//#define OPENIOBUF

namespace FastIO
{
	class FastIOBase
	{
	protected:
#ifdef OPENIOBUF
		static const int BUFSIZE=1<<22;
		char buf[BUFSIZE+1];
		int buf_p=0;
#endif
		FILE *target;
	public:
#ifdef OPENIOBUF
		virtual void flush()=0;
#endif
		FastIOBase(FILE *f): target(f){}
		~FastIOBase()=default;
	};

	class FastOutput: public FastIOBase
	{
#ifdef OPENIOBUF
	public:
		inline void flush()
			{ fwrite(buf,1,buf_p,target),buf_p=0; }
#endif
	protected:
		inline void __putc(char x)
		{
#ifdef OPENIOBUF
			if(buf[buf_p++]=x,buf_p==BUFSIZE)flush();
#else
			putc(x,target);
#endif
		}
		template<typename T>
		inline void __write(T x)
		{
			static char stk[64],*top;top=stk;
			if(x<0) return __putc('-'),__write(-x);
			do *(top++)=x%10,x/=10; while(x);
			for(;top!=stk;__putc(*(--top)+'0'));
		}
	public:
		FastOutput(FILE *f=stdout): FastIOBase(f){}
#ifdef OPENIOBUF
		~FastOutput(){ flush(); }
#endif
		template<typename ...T>
		inline void writesp(const T &...x)
			{ initializer_list<int>{(this->operator<<(x),__putc(' '),0)...}; }
		template<typename ...T>
		inline void writeln(const T &...x)
			{ initializer_list<int>{(this->operator<<(x),__putc('\n'),0)...}; }
		inline FastOutput &operator <<(char x)
			{ return __putc(x),*this; }
		inline FastOutput &operator <<(const char *s)
			{ for(;*s;__putc(*(s++)));return *this; }
		inline FastOutput &operator <<(const string &s)
			{ return (*this)<<s.c_str(); }
		template<typename T,typename=typename enable_if<is_integral<T>::value>::type>
		inline FastOutput &operator <<(const T &x)
			{ return __write(x),*this; }
	}qout;

	class FastInput: public FastIOBase
	{
#ifdef OPENIOBUF
	public:
		inline void flush()
			{ buf[fread(buf,1,BUFSIZE,target)]='\0',buf_p=0; }
#endif
	protected:
		inline char __getc()
		{
#ifdef OPENIOBUF
			if(buf_p==BUFSIZE) flush();
			return buf[buf_p++];
#else
			return getc(target);
#endif
		}
	public:
#ifdef OPENIOBUF
		FastInput(FILE *f=stdin): FastIOBase(f){ buf_p=BUFSIZE; }
#else
		FastInput(FILE *f=stdin): FastIOBase(f){}
#endif
		inline char getchar() { return __getc(); }
		template<typename ...T>
		inline void read(T &...x)
			{ initializer_list<int>{(this->operator>>(x),0)...}; }
		inline FastInput &operator >>(char &x)
			{ while(isspace(x=__getc()));return *this; }
		template<typename T,typename=typename enable_if<is_integral<T>::value>::type>
		inline FastInput &operator >>(T &x)
		{
			static char ch,sym;x=sym=0;
			while(isspace(ch=__getc()));
			if(ch=='-') sym=1,ch=__getc();
			for(;isdigit(ch);x=(x<<1)+(x<<3)+(ch^48),ch=__getc());
			return sym?x=-x:x,*this;
		}
		inline FastInput &operator >>(char *s)
		{
			while(isspace(*s=__getc()));
			for(;!isspace(*s) && *s && ~*s;*(++s)=__getc());
			return *s='\0',*this;
		}
		inline FastInput &operator >>(string &s)
		{
			char str_buf[(1<<8)+1],*p=str_buf;
			char *const buf_end=str_buf+(1<<8);
			while(isspace(*p=__getc()));
			for(s.clear(),p++;;p=str_buf)
			{
				for(;p!=buf_end && !isspace(*p=__getc()) && *p && ~*p;p++);
				*p='\0',s.append(str_buf);
				if(p!=buf_end) break;
			}
			return *this;
		}
	}qin;
}
using namespace FastIO;

using LL=long long;
using LD=long double;
using UI=unsigned int;
using ULL=unsigned long long;

#ifndef DADALZY
#define FILEIO(file) freopen(file".in","r",stdin),freopen(file".out","w",stdout)
#else
#define FILEIO(file)
#endif

int T,oldT;
struct Data
{
	int x,c;
	Data()=default;
	Data(int _x,int _c): x(_x),c(_c){}
	inline bool operator <(const Data &rhs)const
		{ return c>rhs.c; }
};

constexpr int pw10[6]={1,3,2,6,4,5},sp10[6]={0,1,4,6,5,2};
inline bool solve(vector<int> v1,vector<Data> v2)
{
	sort(v1.begin(),v1.end());
	int tmp=pw10[v1.size()%6],x=0;
	for(auto &i: v2) x=(x+tmp*i.x*sp10[i.c%6])%7,tmp=tmp*pw10[i.c%6]%7;
	do
	{
		int y=x;
		for(int i=0;i<v1.size();i++) y=(y+pw10[i%6]*v1[i])%7;
		if(!y)
		{
			reverse(v1.begin(),v1.end());
			reverse(v2.begin(),v2.end());
			if(oldT==3)
			{	
			qout.writeln(v1.size()+v2.size());
			for(auto &i: v2) qout<<i.c<<' '<<i.x<<'\n';
			for(auto &i: v1) qout<<1<<' '<<i<<'\n';
			}
			return true;
		}
	}while(next_permutation(v1.begin(),v1.end()));
	if(oldT==3)
	qout.writeln(-1);
	return false;
}
int main()
{
	qin>>T;oldT=T;
	while(T--)
	{
		vector<Data> vec;
		for(int i=0,x;i<10;i++)
			qin>>x,(x?vec.push_back(Data(i,x)):void());
		sort(vec.begin(),vec.end());
		if(vec.size()==1)
			solve({},vec);
		else if(vec.size()>=2 && vec[0].c>=3 && vec[1].c>=2)
		{
			vector<int> tmp{vec[0].x,vec[0].x,vec[0].x,
							vec[1].x,vec[1].x};
			vec[0].c-=3,vec[1].c-=2;
			solve(tmp,vec);
		}
		else if(vec.size()>=3 && vec[0].c>=2 && vec[1].c>=2)
		{
			vector<int> tmp{vec[0].x,vec[0].x,
							vec[1].x,vec[1].x,vec[2].x};
			vec[0].c-=2,vec[1].c-=2,vec[2].c--;
			solve(tmp,vec);
		}
		else if(vec.size()>=3 && vec[0].c>=5)
		{
			vector<int> tmp{vec[0].x,vec[0].x,vec[0].x,vec[0].x,vec[0].x,
							vec[1].x,vec[2].x};
			vec[0].c-=5,vec[1].c--,vec[2].c--;
			solve(tmp,vec);
		}
		else{ int res1=-1;auto old=vec;if(vec.size()>=4)
		{
			vector<int> tmp{vec[0].x,vec[1].x,
							vec[2].x,vec[3].x};
			vec[0].c--,vec[1].c--,vec[2].c--,vec[3].c--;
			res1=solve(tmp,vec);
			if(oldT==3) continue;
		}
		// else
		{
			vector<int> tmp;
			for(auto &i: old)
				for(int j=0;j<i.c;j++)
					tmp.push_back(i.x);
			int res2=solve(tmp,{});
			if(res1!=-1 && res1!=res2)
			{
				for(auto &i: old)
					cout<<i.c<<' '<<i.x<<'\n';
				return 0;
			}
		}}
	}
	return 0;
}
/*
1
0 0 0 1 0 1 1 1 0 1
1 3
1 5
1 6
1 7
1 9

ans:

*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3608kb

input:

3
0 1 0 0 1 0 0 0 0 0
0 2 0 0 0 0 1 0 0 1
0 1000000000 0 0 0 0 0 0 0 0

output:

2
1 1
1 4
4
1 9
1 6
1 1
1 1
-1

result:

ok T=3

Test #2:

score: -100
Wrong Answer
time: 2ms
memory: 3700kb

input:

100000
0 0 0 1 0 1 1 1 0 1
1 1 0 0 1 0 1 0 1 0
1 1 1 1 0 0 0 1 0 1
0 1 1 0 0 1 1 1 1 0
0 0 1 0 1 0 1 0 1 0
0 1 0 0 0 0 0 1 0 0
1 1 0 0 0 0 0 0 1 1
1 0 1 1 1 0 1 0 0 0
0 1 1 0 0 1 0 1 0 1
1 0 0 1 1 0 0 1 0 0
1 1 0 1 0 0 1 0 1 1
0 0 1 0 0 0 0 1 0 0
0 1 1 1 1 1 1 1 0 1
1 0 0 0 0 1 0 0 0 1
0 0 0 0 1 0 1...

output:

1 1
1 2
1 5
1 8
1 9

result:

wrong answer Participant output c[i]!=input c[i] in test 1