답안 #362136

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
362136 2021-02-01T20:12:59 Z ogibogi2004 Permutation Recovery (info1cup17_permutation) C++14
25 / 100
6 ms 492 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll MAXN=70004;
const ll sq=300;
const ll mod=1e17+3;
ll d[MAXN];
ll d1[MAXN];
ll t[MAXN],n;
ll add(ll a,ll b)
{
	return (a+b+2*mod)%mod;
}
struct block
{
	unordered_map<ll,vector<ll> >mp;
	ll added;
};
block b[sq];
ll p[MAXN];
int main()
{
	cin>>n;
	for(ll i=1;i<=n;i++)
	{    
		string s;
		cin>>s;
		for(ll j=0;j<s.size();j++)
		{
		 	t[i]=((ll)t[i]*10+s[j]-'0')%mod;
		}
	}
	for(ll i=1;i<=n;i++)
	{
		d[i]=add(t[i],-t[i-1]);
		d1[i]=d[i];
	}
	for(ll i=1;i<=n;i++)
	{
		b[i/sq].added=0;
		b[i/sq].mp[d[i]].push_back(i);
	}
	//for(ll i=1;i<=n;i++)cout<<d1[i]<<" ";
	//cout<<endl;
	for(ll j=1;j<=n;j++)
	{
		for(ll l=n/sq;l>=0;l--)
		{
			if(b[l].mp.count(1+b[l].added)&&b[l].mp[1+b[l].added].size()>0)
			{
				ll t=b[l].mp[1+b[l].added].back();
				for(ll i=l+1;i<=n/sq;i++)
				{
					b[i].added=add(b[i].added,d[t]);
				}
				for(ll i=t+1;i<=n&&i%sq!=0;i++)
				{
					d1[i]-=d[t];
				}
				b[l].mp.clear();
				p[t]=j;
				for(ll i=max(1ll,l*sq);i<=n&&i/sq==l;i++)
				{
					if(p[i]==0)b[i/sq].mp[d1[i]].push_back(i);
				}
				break;
			}
		}
		//for(ll i=1;i<=n;i++)cout<<d1[i]<<" ";
		//cout<<endl;
	}
	for(ll i=1;i<=n;i++)
	{
		cout<<p[i]<<" ";
	}
	cout<<endl;
return 0;
}

Compilation message

permutation.cpp: In function 'int main()':
permutation.cpp:28:15: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |   for(ll j=0;j<s.size();j++)
      |              ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 5 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 5 ms 364 KB Output is correct
3 Incorrect 6 ms 492 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 5 ms 364 KB Output is correct
3 Incorrect 6 ms 492 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 5 ms 364 KB Output is correct
3 Incorrect 6 ms 492 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 5 ms 364 KB Output is correct
3 Incorrect 6 ms 492 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 5 ms 364 KB Output is correct
3 Incorrect 6 ms 492 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 5 ms 364 KB Output is correct
3 Incorrect 6 ms 492 KB Output isn't correct
4 Halted 0 ms 0 KB -