답안 #782528

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
782528 2023-07-14T04:18:53 Z Lyrically 정렬하기 (IOI15_sorting) C++17
0 / 100
14 ms 480 KB
#include<bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
int read(){int x;scanf("%d",&x);return x;}
void print(int x){printf("%d\n",x);}
void file(string s)
{
	freopen((s+".in").c_str(),"r",stdin);
	freopen((s+".out").c_str(),"w",stdout);
}
const int mod=998244353;
int r[200005];
int fa[200005];
bool vis[200005];
int findSwapPairs(int n,int s[],int m,int x[],int y[],int p[],int q[])
{
	rep(j,m){p[j]=q[j]=0;}
	if(is_sorted(s,s+n)){return 0;}
	rep(i,m)
	{
		swap(s[x[i]],s[y[i]]);
		rep(j,n)
		{
			//cout<<s[j]<<" ";
			r[j]=s[j];
			fa[s[j]]=j;vis[j]=0;
		}
		//cout<<endl;
		int inv=n;
		int cur=0;
		bool fl=1;
		rep(j,n)
		{
			if(!vis[j])
			{
				inv--;
				//cout<<i<<" "<<j<<endl;
				int now=j;
				while(!vis[now])
				{
					vis[now]=1;
					if(cur==m){fl=0;break;}
					//cout<<now<<" "<<fa[now]<<endl;
					p[cur]=now,q[cur]=fa[now];
					cur++;
					now=fa[now];
				}
				if(!fl){break;}
			}
		}
		rep(j,n){s[j]=r[j];}
		rep(j,m){p[j]=q[j]=0;}
		if(fl&&inv<=i+1)
		{
			return i+1;
		}
	}
	return -1;
}

Compilation message

sorting.cpp: In function 'int read()':
sorting.cpp:7:23: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    7 | int read(){int x;scanf("%d",&x);return x;}
      |                  ~~~~~^~~~~~~~~
sorting.cpp: In function 'void file(std::string)':
sorting.cpp:11:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |  freopen((s+".in").c_str(),"r",stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sorting.cpp:12:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |  freopen((s+".out").c_str(),"w",stdout);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Incorrect 1 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Incorrect 1 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Incorrect 1 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 14 ms 480 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 14 ms 480 KB Output isn't correct
2 Halted 0 ms 0 KB -