Submission #1013116

# Submission time Handle Problem Language Result Execution time Memory
1013116 2024-07-03T08:07:03 Z vjudge1 Slagalica (COCI19_slagalica2) C++17
35 / 70
49 ms 3484 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 (st==en)
			b=1;
	}
	if (!b)
		cout<<-1<<endl;
	else
		for (int i:ans)
			cout<<i<<' ';
	
	return 0;
}

Compilation message

slagalica.cpp: In function 'int main()':
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 0 ms 348 KB Output is correct
2 Incorrect 1 ms 344 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 38 ms 2852 KB Output is correct
2 Correct 49 ms 2540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 2824 KB Output is correct
2 Incorrect 46 ms 2880 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 37 ms 2260 KB Output is correct
2 Correct 39 ms 3148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 34 ms 2300 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 38 ms 2892 KB Output is correct
2 Correct 35 ms 2128 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 2904 KB Output is correct
2 Incorrect 37 ms 2380 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 37 ms 3016 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 46 ms 3484 KB Output is correct
2 Correct 33 ms 2256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 3084 KB Output is correct
2 Incorrect 38 ms 3028 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 44 ms 3232 KB Output is correct
2 Correct 47 ms 2588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 3016 KB Output is correct
2 Correct 33 ms 2516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 38 ms 3020 KB Output is correct
2 Correct 35 ms 2516 KB Output is correct