QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#152776#6680. HeapqzezWA 172ms5004kbC++141.2kb2023-08-28 20:15:512023-08-28 20:15:52

Judging History

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

  • [2023-08-28 20:15:52]
  • 评测
  • 测评结果:WA
  • 用时:172ms
  • 内存:5004kb
  • [2023-08-28 20:15:51]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
template<typename T>
ostream& operator << (ostream &out,const vector<T>&x){
	if(x.empty())return out<<"[]";
	out<<'['<<x[0];
	for(int len=x.size(),i=1;i<len;i++)out<<','<<x[i];
	return out<<']';
}
template<typename T>
vector<T> ary(const T *a,int l,int r){
	return vector<T>{a+l,a+1+r};
}
template<typename T>
void debug(T x){
	cerr<<x<<'\n';
}
template<typename T,typename ...S>
void debug(T x,S ...y){
	cerr<<x<<' ',debug(y...);
}
const int N=1e5+10;
int T,n,a[N],b[N],ans[N];
void get(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	for(int i=1;i<=n;i++)scanf("%d",&b[i]);
	for(int i=n,x;i>=1;i--){
		vector<int>p;
		for(x=i;x&&b[x]!=a[i];x>>=1)p.push_back(x);
		// debug(i,p);
		if(!x){
			puts("Impossible");return;
		}
		bool s1=1,s2=1;
		if(x>1)s1&=b[x]<=a[i],s2&=b[x]>=a[i];
		for(int t:p)s1&=b[t]>a[i],s2&=b[t]<a[i];
		if(!s1&&!s2){
			puts("Impossible");return;
		}
		if(s1)ans[i]=0;
		else ans[i]=1;
		p.push_back(x);
		for(int j=p.size()-1;j>=1;j--)swap(b[p[j]],b[p[j-1]]);
		// debug(ary(b,1,n));
	}
	for(int i=1;i<=n;i++)printf("%d",ans[i]);
	puts("");
}
int main(){
	for(scanf("%d",&T);T--;)get();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

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

output:

0101
Impossible
001

result:

ok 3 lines

Test #2:

score: -100
Wrong Answer
time: 172ms
memory: 5004kb

input:

1118
77
210555 375330 669075 785279 194474 310626 830710 886719 102133 426324 41900 971872 167203 702222 230534 112350 673156 358623 886831 72864 818751 367894 842740 531878 818794 131219 412128 104469 70427 658494 72060 768735 915294 161365 91671 451974 121863 498890 408674 670274 875754 967228 518...

output:

00010011010000000000101000100001100000010000100100001000001000001000101000000
000001000010010
01011010110010010000000100001100100000000000011000000100
0
Impossible
00
010001000000000000110010000000010010101010101000000000001100000010
Impossible
Impossible
010001011
0010000001001000000000110000100100...

result:

wrong answer 1st lines differ - expected: '000101111110101000001010001010...0101001001001000001100111100010', found: '000100110100000000001010001000...0100001000001000001000101000000'