Submission #1013119

# Submission time Handle Problem Language Result Execution time Memory
1013119 2024-07-03T08:09:21 Z vjudge1 Slagalica (COCI19_slagalica2) C++17
70 / 70
45 ms 3436 KB
#include <bits/stdc++.h>

using namespace std;

vector<int> rc[9];
vector<int> val[9];
int en;

pair<int,int> opt(int x)
{
	pair<int,int> ans={1e9+1,-1};
	for (int t:rc[x])
	{
		if (val[t].empty())
			continue;
		if (t<=4)
		{
			if (t==2 || t==3 || !val[5-t].empty())
			{
				if (ans.first>val[t].back())
					ans.first=val[t].back(),ans.second=t;
			}
		}
	}
	if (ans.second==-1)
	{
		for (int t:rc[x])
		{
			if (val[t].empty())
				continue;
			if (t<=4)
				ans.first=val[t].back(),ans.second=t;	
		}
		if (ans.second==-1)
		{
			for (int t:rc[x])
			{
				if (!val[t].empty())
					ans.first=val[t].back(),ans.second=t;
			}
			if (ans.second==-1)
				return ans;
		}
	}
	val[ans.second].pop_back();
	return ans;
}

int main()
{
	rc[1]={3,4,8};
	rc[2]={1,2,7};
	rc[3]={3,4,8};
	rc[4]={1,2,7};
	rc[5]={3,4,8};
	rc[6]={1,2,7};
	rc[7]={7};
	rc[8]={8};
	int n,st,oo;
	cin>>n;
	for (int i=0;i<n;i++)
	{
		int t,a;
		cin>>t>>a;
		val[t].push_back(a);
		if (t==6 || t==5)
			st=t,oo=a;
		else if(t==7 || t==8)
			en=t;
	}
	for (int i=0;i<9;i++)
		sort(val[i].begin(),val[i].end(),greater<int>());
	vector<int> ans={oo};
	bool b=0;
	while (1)
	{
		auto p=opt(st);
		if (p.second==-1)
			break;
		ans.push_back(p.first),st=p.second;
	}
	if (ans.size()==n)
	{
		for (int i:ans)
			cout<<i<<' ';
		cout<<endl;
	}
	else
		cout<<-1<<endl;
	
	return 0;
}

Compilation message

slagalica.cpp: In function 'int main()':
slagalica.cpp:82:16: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   82 |  if (ans.size()==n)
      |      ~~~~~~~~~~^~~
slagalica.cpp:74:7: warning: unused variable 'b' [-Wunused-variable]
   74 |  bool b=0;
      |       ^
slagalica.cpp:59:11: warning: 'oo' may be used uninitialized in this function [-Wmaybe-uninitialized]
   59 |  int n,st,oo;
      |           ^~
slagalica.cpp:77:16: warning: 'st' may be used uninitialized in this function [-Wmaybe-uninitialized]
   77 |   auto p=opt(st);
      |                ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 444 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 38 ms 1872 KB Output is correct
2 Correct 35 ms 1408 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 38 ms 1800 KB Output is correct
2 Correct 34 ms 1356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 38 ms 1100 KB Output is correct
2 Correct 40 ms 2120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 1156 KB Output is correct
2 Correct 45 ms 2904 KB Output is correct
3 Correct 44 ms 3436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 42 ms 1864 KB Output is correct
2 Correct 34 ms 1140 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 1888 KB Output is correct
2 Correct 34 ms 984 KB Output is correct
3 Correct 42 ms 3080 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 34 ms 1484 KB Output is correct
2 Correct 39 ms 3020 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 44 ms 2204 KB Output is correct
2 Correct 32 ms 1308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 36 ms 2128 KB Output is correct
2 Correct 33 ms 1232 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 43 ms 2212 KB Output is correct
2 Correct 36 ms 1484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 1996 KB Output is correct
2 Correct 33 ms 1488 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 2056 KB Output is correct
2 Correct 42 ms 1488 KB Output is correct