답안 #782527

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
782527 2023-07-14T04:18:30 Z Lyrically 정렬하기 (IOI15_sorting) C++17
컴파일 오류
0 ms 0 KB
#include<bits/stdc++.h>
using namespace std;
#define int long long
#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("%lld",&x);return x;}
void print(int x){printf("%lld\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 'long long int read()':
sorting.cpp:8:23: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    8 | int read(){int x;scanf("%lld",&x);return x;}
      |                  ~~~~~^~~~~~~~~~~
sorting.cpp: In function 'void file(std::string)':
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+".in").c_str(),"r",stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sorting.cpp:13:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |  freopen((s+".out").c_str(),"w",stdout);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/bin/ld: /tmp/ccyCyaq1.o: in function `main':
grader.c:(.text.startup+0x4eb): undefined reference to `findSwapPairs(int, int*, int, int*, int*, int*, int*)'
collect2: error: ld returned 1 exit status