QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#473071#2789. SortingRafi220 1ms3996kbC++141.8kb2024-07-11 21:35:242024-07-11 21:35:24

Judging History

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

  • [2024-07-11 21:35:24]
  • 评测
  • 测评结果:0
  • 用时:1ms
  • 内存:3996kb
  • [2024-07-11 21:35:24]
  • 提交

answer

#include "sorting.h"
#include <bits/stdc++.h>
using namespace std;

#ifdef DEBUG
auto&operator<<(auto&o,pair<auto,auto>p){return o<<"("<<p.first<<", "<<p.second<<")";}
auto operator<<(auto&o,auto x)->decltype(x.end(),o){o<<"{";int i=0;for(auto e:x)o<<","+!i++<<e;return o<<"}";}
#define debug(X...)cerr<<"["#X"]: ",[](auto...$){((cerr<<$<<"; "),...)<<endl;}(X)
#else
#define debug(...){}
#endif

#define ll long long
#define ld long double
#define endl '\n'
#define st first
#define nd second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define FOR(i,l,r) for(int i=(l);i<=(r);i++)
#define ROF(i,r,l) for(int i=(r);i>=(l);i--)
int inf=2000000007;
ll infl=1000000000000000007;
ll mod=1000000007;



int findSwapPairs(int n, int S[], int m, int X[], int Y[], int P[], int Q[])
{
    int l=3,r=3,sr,ans=m;
    while(l<=r)
    {
		vector<int>ord(n),p(n),pos(n),odw(n,0);
		FOR(i,0,n-1) 
		{
			ord[i]=i;
			pos[i]=i;
		}
		sr=(l+r)/2;
		FOR(i,0,sr-1) swap(pos[X[i]],pos[Y[i]]); 
		FOR(i,0,n-1) ord[pos[i]]=i;
		FOR(i,0,n-1) p[S[i]]=ord[i];
		FOR(i,0,n-1) debug(p[i]);
		FOR(i,0,n-1) debug(ord[i]);
		vector<pair<int,int>>res;
		FOR(i,0,n-1)
		{
			if(odw[i]) continue;
			int x=i;
			vector<int>V;
			while(!odw[x])
			{
				if(x!=i) V.pb(x);
				debug(i,x);
				odw[x]=1;
				x=p[x];
			}
			for(auto j:V) res.pb({i,j});
		}
		if(sz(res)<=sr)
		{
			ans=sr;
			r=sr-1;
			FOR(i,0,sr-1)
			{
				P[i]=res[i].st;
				Q[i]=res[i].nd;
			}
		}
		else l=sr+1;
	}
	debug(ans);
	vector<int>pos(n);
	FOR(i,0,n-1) pos[S[i]]=i;
	FOR(i,0,ans-1) 
	{
		P[i]=pos[P[i]];
		Q[i]=pos[Q[i]];
		swap(pos[S[P[i]]],pos[S[Q[i]]]);
		swap(S[P[i]],S[Q[i]]);
		swap(pos[S[X[i]]],pos[S[Y[i]]]);
		swap(S[X[i]],S[Y[i]]);
	}
	FOR(i,0,n-1) debug(S[i]);
	return ans;
}



詳細信息

Subtask #1:

score: 0
Runtime Error

Test #1:

score: 0
Runtime Error

input:

1
0
1
0 0

output:

Unauthorized output

result:


Subtask #2:

score: 0
Runtime Error

Test #8:

score: 0
Runtime Error

input:

1
0
30
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0

output:

Unauthorized output

result:


Subtask #3:

score: 0
Wrong Answer

Test #13:

score: 16
Accepted
time: 0ms
memory: 3752kb

input:

2
0 1
60
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1

output:

3
0 1
0 0
1 1

result:

ok correct

Test #14:

score: -16
Wrong Answer
time: 0ms
memory: 3996kb

input:

5
0 4 1 3 2
150
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
...

output:

3
0 2
2 4
4 1

result:

wrong answer the final array is not sorted

Subtask #4:

score: 0
Skipped

Dependency #2:

0%

Subtask #5:

score: 0
Wrong Answer

Test #28:

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

input:

1800
530 1775 466 953 230 1179 944 752 990 1316 275 1029 158 152 1673 1706 172 115 599 1661 131 699 1112 454 551 1059 291 495 28 67 773 480 839 462 1210 757 879 285 439 3 1429 820 26 1023 942 199 356 625 1705 1421 144 1529 716 7 1485 1027 1599 696 517 1353 456 1389 273 1363 1414 1177 718 41 777 1621...

output:

5400
688 688
688 688
688 688
688 688
688 688
688 688
688 688
688 688
688 688
688 688
688 688
688 688
688 688
688 688
688 688
688 688
688 688
688 688
688 688
688 688
688 688
688 688
688 688
688 688
688 688
688 688
688 688
688 688
688 688
688 688
688 688
688 688
688 688
688 688
688 688
688 688
688 688...

result:

wrong answer the final array is not sorted

Subtask #6:

score: 0
Skipped

Dependency #5:

0%