Submission #128314

# Submission time Handle Problem Language Result Execution time Memory
128314 2019-07-10T16:35:49 Z mohammedehab2002 Minerals (JOI19_minerals) C++14
100 / 100
151 ms 4004 KB
#include "minerals.h"
#include <vector>
using namespace std;
int cur=0;
pair<int,int> dp[43005][2];
vector<int> v1,v2;
bool query(int x)
{
	int tmp=Query(x);
	if (cur==tmp)
	return 1;
	cur=tmp;
	return 0;
}
void solve(vector<int> a,vector<int> b,bool added)
{
	if (a.empty())
	return;
	if (a.size()==1)
	{
		Answer(a[0],b[0]);
		return;
	}
	int mid=dp[a.size()][added].second;
	if (a.size()>6000)
	{
		mid=(15*a.size()+4)/24;
		if (!added)
		mid=(9*a.size()+4)/24;
	}
	vector<int> aa[2],bb[2];
	for (int i=0;i<a.size();i++)
	{
		if (i<mid)
		{
			aa[0].push_back(a[i]);
			if (!added)
			query(a[i]);
		}
		else
		{
			aa[1].push_back(a[i]);
			if (added)
			query(a[i]);
		}
	}
	for (int i=0;i<b.size()-1;i++)
	{
		if (query(b[i]))
		bb[0].push_back(b[i]);
		else
		bb[1].push_back(b[i]);
	}
	if (aa[0].size()==bb[0].size())
	bb[1].push_back(b.back());
	else
	bb[0].push_back(b.back());
	solve(aa[0],bb[0],1);
	solve(aa[1],bb[1],0);
}
void Solve(int n)
{
	for (int i=1;i<=2*n;i++)
	{
		if (query(i))
		v2.push_back(i);
		else
		v1.push_back(i);	
	}
	for (int i=2;i<=6000;i++)
	{
		dp[i][0]={1e9,-1};
		dp[i][1]={1e9,-1};
		for (int j=1;j<=i-1;j++)
		{
			dp[i][0]=min(dp[i][0],{dp[j][1].first+dp[i-j][0].first+j+i-1,j});
			dp[i][1]=min(dp[i][1],{dp[j][1].first+dp[i-j][0].first+i-j+i-1,j});
		}
	}
	solve(v1,v2,1);
}

Compilation message

minerals.cpp: In function 'void solve(std::vector<int>, std::vector<int>, bool)':
minerals.cpp:32:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i=0;i<a.size();i++)
               ~^~~~~~~~~
minerals.cpp:47:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i=0;i<b.size()-1;i++)
               ~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 75 ms 376 KB Output is correct
2 Correct 76 ms 608 KB Output is correct
3 Correct 75 ms 376 KB Output is correct
4 Correct 76 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 77 ms 424 KB Output is correct
2 Correct 78 ms 552 KB Output is correct
3 Correct 81 ms 632 KB Output is correct
4 Correct 86 ms 1088 KB Output is correct
5 Correct 96 ms 1548 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 75 ms 376 KB Output is correct
2 Correct 76 ms 608 KB Output is correct
3 Correct 75 ms 376 KB Output is correct
4 Correct 76 ms 376 KB Output is correct
5 Correct 77 ms 424 KB Output is correct
6 Correct 78 ms 552 KB Output is correct
7 Correct 81 ms 632 KB Output is correct
8 Correct 86 ms 1088 KB Output is correct
9 Correct 96 ms 1548 KB Output is correct
10 Correct 77 ms 504 KB Output is correct
11 Correct 90 ms 1144 KB Output is correct
12 Correct 99 ms 1684 KB Output is correct
13 Correct 94 ms 1784 KB Output is correct
14 Correct 92 ms 1484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 75 ms 376 KB Output is correct
2 Correct 76 ms 608 KB Output is correct
3 Correct 75 ms 376 KB Output is correct
4 Correct 76 ms 376 KB Output is correct
5 Correct 77 ms 424 KB Output is correct
6 Correct 78 ms 552 KB Output is correct
7 Correct 81 ms 632 KB Output is correct
8 Correct 86 ms 1088 KB Output is correct
9 Correct 96 ms 1548 KB Output is correct
10 Correct 77 ms 504 KB Output is correct
11 Correct 90 ms 1144 KB Output is correct
12 Correct 99 ms 1684 KB Output is correct
13 Correct 94 ms 1784 KB Output is correct
14 Correct 92 ms 1484 KB Output is correct
15 Correct 136 ms 3620 KB Output is correct
16 Correct 136 ms 3544 KB Output is correct
17 Correct 131 ms 3344 KB Output is correct
18 Correct 124 ms 3272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 75 ms 376 KB Output is correct
2 Correct 76 ms 608 KB Output is correct
3 Correct 75 ms 376 KB Output is correct
4 Correct 76 ms 376 KB Output is correct
5 Correct 77 ms 424 KB Output is correct
6 Correct 78 ms 552 KB Output is correct
7 Correct 81 ms 632 KB Output is correct
8 Correct 86 ms 1088 KB Output is correct
9 Correct 96 ms 1548 KB Output is correct
10 Correct 77 ms 504 KB Output is correct
11 Correct 90 ms 1144 KB Output is correct
12 Correct 99 ms 1684 KB Output is correct
13 Correct 94 ms 1784 KB Output is correct
14 Correct 92 ms 1484 KB Output is correct
15 Correct 136 ms 3620 KB Output is correct
16 Correct 136 ms 3544 KB Output is correct
17 Correct 131 ms 3344 KB Output is correct
18 Correct 124 ms 3272 KB Output is correct
19 Correct 148 ms 3568 KB Output is correct
20 Correct 138 ms 3572 KB Output is correct
21 Correct 133 ms 3516 KB Output is correct
22 Correct 128 ms 3304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 75 ms 376 KB Output is correct
2 Correct 76 ms 608 KB Output is correct
3 Correct 75 ms 376 KB Output is correct
4 Correct 76 ms 376 KB Output is correct
5 Correct 77 ms 424 KB Output is correct
6 Correct 78 ms 552 KB Output is correct
7 Correct 81 ms 632 KB Output is correct
8 Correct 86 ms 1088 KB Output is correct
9 Correct 96 ms 1548 KB Output is correct
10 Correct 77 ms 504 KB Output is correct
11 Correct 90 ms 1144 KB Output is correct
12 Correct 99 ms 1684 KB Output is correct
13 Correct 94 ms 1784 KB Output is correct
14 Correct 92 ms 1484 KB Output is correct
15 Correct 136 ms 3620 KB Output is correct
16 Correct 136 ms 3544 KB Output is correct
17 Correct 131 ms 3344 KB Output is correct
18 Correct 124 ms 3272 KB Output is correct
19 Correct 148 ms 3568 KB Output is correct
20 Correct 138 ms 3572 KB Output is correct
21 Correct 133 ms 3516 KB Output is correct
22 Correct 128 ms 3304 KB Output is correct
23 Correct 142 ms 3748 KB Output is correct
24 Correct 145 ms 3800 KB Output is correct
25 Correct 132 ms 3576 KB Output is correct
26 Correct 125 ms 3396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 75 ms 376 KB Output is correct
2 Correct 76 ms 608 KB Output is correct
3 Correct 75 ms 376 KB Output is correct
4 Correct 76 ms 376 KB Output is correct
5 Correct 77 ms 424 KB Output is correct
6 Correct 78 ms 552 KB Output is correct
7 Correct 81 ms 632 KB Output is correct
8 Correct 86 ms 1088 KB Output is correct
9 Correct 96 ms 1548 KB Output is correct
10 Correct 77 ms 504 KB Output is correct
11 Correct 90 ms 1144 KB Output is correct
12 Correct 99 ms 1684 KB Output is correct
13 Correct 94 ms 1784 KB Output is correct
14 Correct 92 ms 1484 KB Output is correct
15 Correct 136 ms 3620 KB Output is correct
16 Correct 136 ms 3544 KB Output is correct
17 Correct 131 ms 3344 KB Output is correct
18 Correct 124 ms 3272 KB Output is correct
19 Correct 148 ms 3568 KB Output is correct
20 Correct 138 ms 3572 KB Output is correct
21 Correct 133 ms 3516 KB Output is correct
22 Correct 128 ms 3304 KB Output is correct
23 Correct 142 ms 3748 KB Output is correct
24 Correct 145 ms 3800 KB Output is correct
25 Correct 132 ms 3576 KB Output is correct
26 Correct 125 ms 3396 KB Output is correct
27 Correct 141 ms 3772 KB Output is correct
28 Correct 140 ms 3852 KB Output is correct
29 Correct 141 ms 3544 KB Output is correct
30 Correct 127 ms 3352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 75 ms 376 KB Output is correct
2 Correct 76 ms 608 KB Output is correct
3 Correct 75 ms 376 KB Output is correct
4 Correct 76 ms 376 KB Output is correct
5 Correct 77 ms 424 KB Output is correct
6 Correct 78 ms 552 KB Output is correct
7 Correct 81 ms 632 KB Output is correct
8 Correct 86 ms 1088 KB Output is correct
9 Correct 96 ms 1548 KB Output is correct
10 Correct 77 ms 504 KB Output is correct
11 Correct 90 ms 1144 KB Output is correct
12 Correct 99 ms 1684 KB Output is correct
13 Correct 94 ms 1784 KB Output is correct
14 Correct 92 ms 1484 KB Output is correct
15 Correct 136 ms 3620 KB Output is correct
16 Correct 136 ms 3544 KB Output is correct
17 Correct 131 ms 3344 KB Output is correct
18 Correct 124 ms 3272 KB Output is correct
19 Correct 148 ms 3568 KB Output is correct
20 Correct 138 ms 3572 KB Output is correct
21 Correct 133 ms 3516 KB Output is correct
22 Correct 128 ms 3304 KB Output is correct
23 Correct 142 ms 3748 KB Output is correct
24 Correct 145 ms 3800 KB Output is correct
25 Correct 132 ms 3576 KB Output is correct
26 Correct 125 ms 3396 KB Output is correct
27 Correct 141 ms 3772 KB Output is correct
28 Correct 140 ms 3852 KB Output is correct
29 Correct 141 ms 3544 KB Output is correct
30 Correct 127 ms 3352 KB Output is correct
31 Correct 143 ms 4004 KB Output is correct
32 Correct 143 ms 3920 KB Output is correct
33 Correct 133 ms 3612 KB Output is correct
34 Correct 135 ms 3504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 75 ms 376 KB Output is correct
2 Correct 76 ms 608 KB Output is correct
3 Correct 75 ms 376 KB Output is correct
4 Correct 76 ms 376 KB Output is correct
5 Correct 77 ms 424 KB Output is correct
6 Correct 78 ms 552 KB Output is correct
7 Correct 81 ms 632 KB Output is correct
8 Correct 86 ms 1088 KB Output is correct
9 Correct 96 ms 1548 KB Output is correct
10 Correct 77 ms 504 KB Output is correct
11 Correct 90 ms 1144 KB Output is correct
12 Correct 99 ms 1684 KB Output is correct
13 Correct 94 ms 1784 KB Output is correct
14 Correct 92 ms 1484 KB Output is correct
15 Correct 136 ms 3620 KB Output is correct
16 Correct 136 ms 3544 KB Output is correct
17 Correct 131 ms 3344 KB Output is correct
18 Correct 124 ms 3272 KB Output is correct
19 Correct 148 ms 3568 KB Output is correct
20 Correct 138 ms 3572 KB Output is correct
21 Correct 133 ms 3516 KB Output is correct
22 Correct 128 ms 3304 KB Output is correct
23 Correct 142 ms 3748 KB Output is correct
24 Correct 145 ms 3800 KB Output is correct
25 Correct 132 ms 3576 KB Output is correct
26 Correct 125 ms 3396 KB Output is correct
27 Correct 141 ms 3772 KB Output is correct
28 Correct 140 ms 3852 KB Output is correct
29 Correct 141 ms 3544 KB Output is correct
30 Correct 127 ms 3352 KB Output is correct
31 Correct 143 ms 4004 KB Output is correct
32 Correct 143 ms 3920 KB Output is correct
33 Correct 133 ms 3612 KB Output is correct
34 Correct 135 ms 3504 KB Output is correct
35 Correct 148 ms 3956 KB Output is correct
36 Correct 151 ms 3912 KB Output is correct
37 Correct 132 ms 3652 KB Output is correct
38 Correct 131 ms 3512 KB Output is correct