Submission #1193956

#TimeUsernameProblemLanguageResultExecution timeMemory
1193956SmuggingSpunSlagalica (COCI19_slagalica2)C++20
10 / 70
15 ms1096 KiB
#include<bits/stdc++.h>
#define taskname "B"
using namespace std;
template<class T>bool minimize(T& a, T b){
	if(a > b){
		a = b;
		return true;
	}
	return false;
}
const int cr[8][8] = {
	{0, 0, 1, 1, 0, 0, 0, 1},
	{1, 1, 0, 0, 0, 0, 1, 0},
	{0, 0, 1, 1, 0, 0, 0, 1},
	{1, 1, 0, 0, 0, 0, 1, 0},
	{0, 0, 1, 1, 0, 0, 0, 1},
	{1, 1, 0, 0, 0, 0, 1, 0},
	{0, 0, 0, 0, 1, 1, 0, 0},
	{0, 0, 0, 0, 1, 1, 0, 0}
};
const int lim = 1e5 + 5;
int n, t[lim], a[lim];
namespace sub12{
	void solve(){
		vector<int>p(n), best, ans;
		iota(p.begin(), p.end(), 1);
		do{
			if(t[p[0]] == 4 || t[p[0]] == 5){
				bool flag = true;
				for(int i = 1; i < n; i++){
					if(cr[t[p[i - 1]]][t[p[i]]] == 0){
						flag = false;
						break;
					}
				}
				if(flag){
					vector<int>pattern;
					for(int i = 0; i < n; i++){
						pattern.emplace_back(a[p[i]]);
					}
					if(best.empty()){
						best = pattern;
					}
					minimize(best, pattern);
					if(best == pattern){
						ans = p;
					}					
				}
			}
		} while(next_permutation(p.begin(), p.end()));
		if(ans.empty()){
			cout << "-1";
		}
		for(int& x : ans){
			cout << a[x] << " ";
		}
	}
}
namespace sub345{
	void solve(){
		
	}
}
int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	if(fopen(taskname".inp", "r")){
		freopen(taskname".inp", "r", stdin);
	}
	cin >> n;
	for(int i = 1; i <= n; i++){
		cin >> t[i] >> a[i];
		t[i]--;
	}
	if(n <= 10){
		sub12::solve();
	}
	else{
		sub345::solve();
	}
}

Compilation message (stderr)

slagalica.cpp: In function 'int main()':
slagalica.cpp:67:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   67 |                 freopen(taskname".inp", "r", stdin);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...