Submission #71437

# Submission time Handle Problem Language Result Execution time Memory
71437 2018-08-24T14:54:00 Z zscoder Rope (JOI17_rope) C++17
45 / 100
2500 ms 8704 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
 
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> pbds;

set<string> S;
const int N = 20;
void gen()
{
	queue<string> q;
	q.push("10");S.insert("10");
	q.push("11");S.insert("11");
	q.push("00");S.insert("00");
	while(!q.empty())
	{
		string s=q.front(); q.pop();
		for(int i=0;i<s.length();i++)
		{
			string t=s.substr(0,i+1);
			reverse(t.begin(),t.end());
			t+=s;
			if(t.length()<=N&&S.find(t)==S.end())
			{
				S.insert(t); q.push(t);
			}
		}
		reverse(s.begin(),s.end());
		if(s.length()<=N&&S.find(s)==S.end())
		{
			S.insert(s); q.push(s);
		}
	}
}

int a[1111111];
int ans[1111111];
vector<vi> dp;

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	//gen();
	//int n; cin>>n;
	/*
	for(auto s:S)
	{
		if(int(s.length())<=n)
		{
			cout<<s<<'\n';
		}
	}
	*/
	/*
	vector<string> L,R;
	for(int i=0;i<(1<<n);i++)
	{
		string s; 
		for(int j=n-1;j>=0;j--)
		{
			if(i&(1<<j)) s+='1';
			else s+='0';
		}
		if(S.find(s)!=S.end())
		{
			R.pb(s);
		}
		else
		{
			L.pb(s);
		}
	}
	cerr<<"ACCEPTED\n";
	for(auto s:R)
	{
		for(int j=0;j<s.length();j+=2)
		{
			int cur=s[j]-'0'; int nxt=s[j+1]-'0';
			cerr<<cur*2+nxt;
		}
		cerr<<'\n';
	}
	cerr<<'\n';
	*/
	int n,m; cin>>n>>m;
	for(int i=0;i<m;i++) ans[i]=int(1e9);
	for(int i=0;i<n;i++)
	{
		cin>>a[i]; a[i]--;
	}
	for(int i=0;i<m;i++)
	{
		for(int j=i;j<m;j++)
		{
			//all 0 or 3
			int mx=0;
			if(n&1) mx+=(a[0]==i||a[0]==j);
			for(int k=(n&1);k<n;k+=2)
			{
				mx+=max((a[k]==i)+(a[k+1]==i),(a[k]==j)+(a[k+1]==j));
			}
			//special pattern
			{
				int as = 0;
				dp.resize(n);
				for(int i=0;i<n;i++) dp[i].assign(4,-int(1e9));
				if(n&1)
				{
					dp[0][0] = (a[0]==i);
					dp[0][1] = (a[0]==j);
				}
				for(int k=(n&1);k<n;k+=2)
				{
					for(int l=0;l<4;l++)
					{
						if(k==0)
						{
							dp[k][l]=0;
						}
						else
						{
							if(l==0) 
							{
								dp[k][l]=max(dp[max(k-2,0)][0], dp[max(k-2,0)][2]);
							}
							else if(l==1)
							{
								dp[k][l]=max(dp[max(k-2,0)][0], dp[max(k-2,0)][2]);
							}
							else if(l==2)
							{
								dp[k][l]=max(dp[max(k-2,0)][1], dp[max(k-2,0)][3]);
							}
							else
							{
								dp[k][l]=max(dp[max(k-2,0)][3],dp[max(k-2,0)][1]);
							}
						}
						dp[k][l]+=(l&1?a[k+1]==j:a[k+1]==i);
						dp[k][l]+=(l/2?a[k]==j:a[k]==i);
					}
				}
				for(int i=0;i<4;i++) as=max(as,dp[n-2][i]);
				mx=max(mx,as);
			}
			ans[i]=min(ans[i],n-mx); ans[j]=min(ans[j],n-mx);
		}
	}	
	for(int i=0;i<m;i++)
	{
		cout<<ans[i]<<'\n';
	}
}	

Compilation message

rope.cpp: In function 'void gen()':
rope.cpp:30:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i=0;i<s.length();i++)
               ~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 4 ms 528 KB Output is correct
3 Correct 2 ms 640 KB Output is correct
4 Correct 3 ms 640 KB Output is correct
5 Correct 4 ms 640 KB Output is correct
6 Correct 2 ms 676 KB Output is correct
7 Correct 3 ms 676 KB Output is correct
8 Correct 4 ms 676 KB Output is correct
9 Correct 3 ms 776 KB Output is correct
10 Correct 2 ms 776 KB Output is correct
11 Correct 3 ms 804 KB Output is correct
12 Correct 2 ms 804 KB Output is correct
13 Correct 3 ms 804 KB Output is correct
14 Correct 3 ms 804 KB Output is correct
15 Correct 3 ms 804 KB Output is correct
16 Correct 4 ms 808 KB Output is correct
17 Correct 3 ms 808 KB Output is correct
18 Correct 2 ms 892 KB Output is correct
19 Correct 3 ms 892 KB Output is correct
20 Correct 3 ms 892 KB Output is correct
21 Correct 2 ms 892 KB Output is correct
22 Correct 2 ms 892 KB Output is correct
23 Correct 3 ms 892 KB Output is correct
24 Correct 3 ms 892 KB Output is correct
25 Correct 3 ms 892 KB Output is correct
26 Correct 2 ms 892 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 4 ms 528 KB Output is correct
3 Correct 2 ms 640 KB Output is correct
4 Correct 3 ms 640 KB Output is correct
5 Correct 4 ms 640 KB Output is correct
6 Correct 2 ms 676 KB Output is correct
7 Correct 3 ms 676 KB Output is correct
8 Correct 4 ms 676 KB Output is correct
9 Correct 3 ms 776 KB Output is correct
10 Correct 2 ms 776 KB Output is correct
11 Correct 3 ms 804 KB Output is correct
12 Correct 2 ms 804 KB Output is correct
13 Correct 3 ms 804 KB Output is correct
14 Correct 3 ms 804 KB Output is correct
15 Correct 3 ms 804 KB Output is correct
16 Correct 4 ms 808 KB Output is correct
17 Correct 3 ms 808 KB Output is correct
18 Correct 2 ms 892 KB Output is correct
19 Correct 3 ms 892 KB Output is correct
20 Correct 3 ms 892 KB Output is correct
21 Correct 2 ms 892 KB Output is correct
22 Correct 2 ms 892 KB Output is correct
23 Correct 3 ms 892 KB Output is correct
24 Correct 3 ms 892 KB Output is correct
25 Correct 3 ms 892 KB Output is correct
26 Correct 2 ms 892 KB Output is correct
27 Correct 147 ms 6868 KB Output is correct
28 Correct 60 ms 7204 KB Output is correct
29 Correct 118 ms 7288 KB Output is correct
30 Correct 70 ms 7516 KB Output is correct
31 Correct 177 ms 7696 KB Output is correct
32 Correct 48 ms 7904 KB Output is correct
33 Correct 120 ms 8132 KB Output is correct
34 Correct 64 ms 8340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 4 ms 528 KB Output is correct
3 Correct 2 ms 640 KB Output is correct
4 Correct 3 ms 640 KB Output is correct
5 Correct 4 ms 640 KB Output is correct
6 Correct 2 ms 676 KB Output is correct
7 Correct 3 ms 676 KB Output is correct
8 Correct 4 ms 676 KB Output is correct
9 Correct 3 ms 776 KB Output is correct
10 Correct 2 ms 776 KB Output is correct
11 Correct 3 ms 804 KB Output is correct
12 Correct 2 ms 804 KB Output is correct
13 Correct 3 ms 804 KB Output is correct
14 Correct 3 ms 804 KB Output is correct
15 Correct 3 ms 804 KB Output is correct
16 Correct 4 ms 808 KB Output is correct
17 Correct 3 ms 808 KB Output is correct
18 Correct 2 ms 892 KB Output is correct
19 Correct 3 ms 892 KB Output is correct
20 Correct 3 ms 892 KB Output is correct
21 Correct 2 ms 892 KB Output is correct
22 Correct 2 ms 892 KB Output is correct
23 Correct 3 ms 892 KB Output is correct
24 Correct 3 ms 892 KB Output is correct
25 Correct 3 ms 892 KB Output is correct
26 Correct 2 ms 892 KB Output is correct
27 Correct 147 ms 6868 KB Output is correct
28 Correct 60 ms 7204 KB Output is correct
29 Correct 118 ms 7288 KB Output is correct
30 Correct 70 ms 7516 KB Output is correct
31 Correct 177 ms 7696 KB Output is correct
32 Correct 48 ms 7904 KB Output is correct
33 Correct 120 ms 8132 KB Output is correct
34 Correct 64 ms 8340 KB Output is correct
35 Execution timed out 2555 ms 8704 KB Time limit exceeded
36 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 4 ms 528 KB Output is correct
3 Correct 2 ms 640 KB Output is correct
4 Correct 3 ms 640 KB Output is correct
5 Correct 4 ms 640 KB Output is correct
6 Correct 2 ms 676 KB Output is correct
7 Correct 3 ms 676 KB Output is correct
8 Correct 4 ms 676 KB Output is correct
9 Correct 3 ms 776 KB Output is correct
10 Correct 2 ms 776 KB Output is correct
11 Correct 3 ms 804 KB Output is correct
12 Correct 2 ms 804 KB Output is correct
13 Correct 3 ms 804 KB Output is correct
14 Correct 3 ms 804 KB Output is correct
15 Correct 3 ms 804 KB Output is correct
16 Correct 4 ms 808 KB Output is correct
17 Correct 3 ms 808 KB Output is correct
18 Correct 2 ms 892 KB Output is correct
19 Correct 3 ms 892 KB Output is correct
20 Correct 3 ms 892 KB Output is correct
21 Correct 2 ms 892 KB Output is correct
22 Correct 2 ms 892 KB Output is correct
23 Correct 3 ms 892 KB Output is correct
24 Correct 3 ms 892 KB Output is correct
25 Correct 3 ms 892 KB Output is correct
26 Correct 2 ms 892 KB Output is correct
27 Correct 147 ms 6868 KB Output is correct
28 Correct 60 ms 7204 KB Output is correct
29 Correct 118 ms 7288 KB Output is correct
30 Correct 70 ms 7516 KB Output is correct
31 Correct 177 ms 7696 KB Output is correct
32 Correct 48 ms 7904 KB Output is correct
33 Correct 120 ms 8132 KB Output is correct
34 Correct 64 ms 8340 KB Output is correct
35 Execution timed out 2555 ms 8704 KB Time limit exceeded
36 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 4 ms 528 KB Output is correct
3 Correct 2 ms 640 KB Output is correct
4 Correct 3 ms 640 KB Output is correct
5 Correct 4 ms 640 KB Output is correct
6 Correct 2 ms 676 KB Output is correct
7 Correct 3 ms 676 KB Output is correct
8 Correct 4 ms 676 KB Output is correct
9 Correct 3 ms 776 KB Output is correct
10 Correct 2 ms 776 KB Output is correct
11 Correct 3 ms 804 KB Output is correct
12 Correct 2 ms 804 KB Output is correct
13 Correct 3 ms 804 KB Output is correct
14 Correct 3 ms 804 KB Output is correct
15 Correct 3 ms 804 KB Output is correct
16 Correct 4 ms 808 KB Output is correct
17 Correct 3 ms 808 KB Output is correct
18 Correct 2 ms 892 KB Output is correct
19 Correct 3 ms 892 KB Output is correct
20 Correct 3 ms 892 KB Output is correct
21 Correct 2 ms 892 KB Output is correct
22 Correct 2 ms 892 KB Output is correct
23 Correct 3 ms 892 KB Output is correct
24 Correct 3 ms 892 KB Output is correct
25 Correct 3 ms 892 KB Output is correct
26 Correct 2 ms 892 KB Output is correct
27 Correct 147 ms 6868 KB Output is correct
28 Correct 60 ms 7204 KB Output is correct
29 Correct 118 ms 7288 KB Output is correct
30 Correct 70 ms 7516 KB Output is correct
31 Correct 177 ms 7696 KB Output is correct
32 Correct 48 ms 7904 KB Output is correct
33 Correct 120 ms 8132 KB Output is correct
34 Correct 64 ms 8340 KB Output is correct
35 Execution timed out 2555 ms 8704 KB Time limit exceeded
36 Halted 0 ms 0 KB -