답안 #804305

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
804305 2023-08-03T07:56:36 Z dungz Kralj (COCI16_kralj) C++17
0 / 140
21 ms 24416 KB
#pragma GCC optimize ("O2")
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define fi first
#define se second
#define endl '\n'
#define task "task"
#define task "task"
#define prll pair<ll,ll>
#define pb push_back
#define ld long double
const ll MIN=-1e18,MAX=1e18,MOD=1e9+7;
vector<int> f[500005];
int n,st2;
int pos[500005];
int val[500005];
set<int> fuck,fuck2;
int con(ll x){
	int temp=x%n;
	if(temp==0) return n;
	else return temp;
}
int main(){
	#ifndef ONLINE_JUDGE
   		freopen (task".inp", "r", stdin);
   		freopen (task".out", "w", stdout);
	#endif
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>pos[i];
		st2=pos[i];
	}	
	for(int i=1;i<=n;i++)
	{
		cin>>val[i];
	}
	for(int i=1;i<=n;i++)
	{
		int x;
		cin>>x;
		f[pos[i]].push_back(x);
	}
	 int st=st2;
	 int ed=st2;
	 int rem=f[st2].size()-1;
	 st2=con(st2+1);
	 while(st2!=ed)
	 {
	 	rem+=f[st2].size()-1;
	 	if(rem<0)
	 	{
	 		st=-1;
	 		rem=0;
	 	}
	 	else if(st==-1)
	 	{
	 		st=st2;
	 	}
	 	st2=con(st2+1);
	 }
	 ed=st;
	 fuck.insert(val[st]);
	 for(auto i:f[st]) fuck2.insert(i);
	 int ans=0,dem=1;
	 st=con(st+1);
	 while(st!=ed)
	 {
	 	// cerr<<st<<endl;
	 	if(f[st].size()!=0)
	 	{
	 		for(auto i:fuck)
	 		{
	 			if(fuck2.empty()) break;
				auto pos=fuck2.lower_bound(i);
	 			if(pos!=fuck2.end())
	 			{
	 				dem--;
	 				ans+=1;
	 				fuck2.erase(pos);
	 			}
	 		}
	 		while(dem and !fuck2.empty())
	 		{
	 			fuck2.erase(fuck2.begin());
	 			dem--;
	 		}
	 		dem=0;
	 	}
	 	for(auto i:f[st]) fuck2.insert(i);
	 	fuck.insert(val[st]);
	 	dem++;
	 	st=con(st+1);
	 }
	for(auto i:fuck)
	{
		if(fuck2.empty()) break;
		auto pos=fuck2.lower_bound(i);
		if(pos!=fuck2.end())
		{
			ans+=1;
			fuck2.erase(pos);
		}
	}
	 cout<<ans;
}
/*

*/

Compilation message

kralj.cpp: In function 'int main()':
kralj.cpp:26:14: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |      freopen (task".inp", "r", stdin);
      |      ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
kralj.cpp:27:14: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |      freopen (task".out", "w", stdout);
      |      ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 18 ms 24404 KB Execution killed with signal 8
2 Runtime error 17 ms 24360 KB Execution killed with signal 8
3 Runtime error 18 ms 24348 KB Execution killed with signal 8
4 Runtime error 17 ms 24320 KB Execution killed with signal 8
5 Runtime error 21 ms 24404 KB Execution killed with signal 8
6 Runtime error 17 ms 24400 KB Execution killed with signal 8
7 Runtime error 17 ms 24416 KB Execution killed with signal 8
8 Runtime error 17 ms 24404 KB Execution killed with signal 8
9 Runtime error 17 ms 24392 KB Execution killed with signal 8
10 Runtime error 16 ms 24352 KB Execution killed with signal 8