Submission #711706

# Submission time Handle Problem Language Result Execution time Memory
711706 2023-03-17T11:27:42 Z william950615 Slagalica (COCI19_slagalica2) C++14
5 / 70
140 ms 10060 KB
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define MEM(x) memset(x, 0, sizeof(x))
#define ALL(x) begin(x), end(x)
#define REP(i,n,...) for( int i = 0, ##__VA_ARGS__; i < n; ++i )
#define FOR(i,a,b,...) for( int i = (a), ##__VA_ARGS__; i <=(b); ++i)
#define RFOR(i,a,b,...) for( int i = (a), ##__VA_ARGS__; i >=(b); --i)
#define EB emplace_back
#define EP emplace_back
#define mkp make_pair
#define SZ(x) int(x.size())


#ifdef DEBUG
	template<typename T> void _DO(T&&x) {cerr << x<< '\n';}
	template<typename A, typename ...B> void _DO(A&&a, B&&...b) {
		cerr <<a << ',';
		_DO(b...);
	}
	#define de(...) do{\
		fprintf(stderr, "%s-%d (%s):", __func__, __LINE__, #__VA_ARGS__);\
		_DO(__VA_ARGS__);\
	}while(0);
#else
	#define de(...)
#endif
typedef long long ll;
typedef pair<int,int> pii;
template<typename T>
using V = vector<T>;

inline void solve() {
	int N; cin >> N;
	set< pair<int,int> > st[ 3 ]; // val, jump to
	set< pair<int,int> > slf[ 3 ];
	int stcnt, edcnt;
	stcnt = edcnt = 0;
	int ct[ 3 ] = {0, 0, 0};
	REP(i,N) {
		int x, val;
		cin >> x >> val;
		de( x, val );

		if( x == 1 ) 
			st[1] .insert( mkp( val, 0 ) ), ct[ 0 ]++;
		if( x == 2 ) 
			st[1] .insert( mkp( val, 1 ) ), slf[ 1 ].insert( mkp( val, 1 ));
		if( x == 4 ) 
			st[0] .insert( mkp( val, 1 ) ), ct[ 1 ]++;
		if( x == 3 ) 
			st[0] .insert( mkp( val, 0 ) ), slf[ 0 ].insert( mkp(val, 0 ));;
		if( x == 5 )  
			st[2] .insert( mkp( val, 0 ) );
		if( x == 6 ) 
			st[2] .insert( mkp( val, 1 ));
		if( x == 7 ) 
			st[1] .insert( mkp( val, 2 ));
		if( x == 8 ) 
			st[0].insert( mkp( val, 2));
	}


	V<int> ans;
	int np = 2;
	int lst = 2;
	while( !st[ np ].empty() ) {
		auto p = *st[ np ].begin(); 	
		de( "start", np, ans.back(), p.F, p.S );
		if( np != p.S && np != 2 ) {
			if( ct[ p.S ] == 1 && !slf[ np ].empty() ) {
				auto newp = *slf[ np ].begin();
				de("ENDD", newp.F, newp.S );
				ans.push_back( newp.F );
				st[ np ].erase( newp );
				slf[ np ].erase( newp );
				lst = np;
				continue;
			}
			else {
				ct[ p.S ]--;
			}
		}	
		ans.push_back( p.F );
		st[ np ].erase( st[ np ].begin() );
		if( np == p.S ) slf[ np ].erase( p );
		np = p.S;
		lst = np;
	}
	if( ans.size() != N  || lst != 2) {
		cout << -1 << '\n';
		return;
	}
	for( auto &i : ans ) {
		cout << i << ' ';
	}
	cout << '\n';;
}
int main () {
	int T = 1;
#ifdef Local
	cin >> T;
#endif
	while(T--) solve();
}

Compilation message

slagalica.cpp: In function 'void solve()':
slagalica.cpp:92:17: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   92 |  if( ans.size() != N  || lst != 2) {
      |      ~~~~~~~~~~~^~~~
slagalica.cpp:39:6: warning: variable 'stcnt' set but not used [-Wunused-but-set-variable]
   39 |  int stcnt, edcnt;
      |      ^~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 72 ms 4644 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 70 ms 4680 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 140 ms 10060 KB Output is correct
2 Incorrect 113 ms 9032 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 98 ms 8464 KB Output is correct
2 Incorrect 103 ms 8372 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 108 ms 8740 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 91 ms 8528 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 82 ms 5948 KB Output is correct
2 Incorrect 90 ms 5684 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 108 ms 7188 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 83 ms 5656 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 139 ms 8036 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 82 ms 5864 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 93 ms 6372 KB Output isn't correct
2 Halted 0 ms 0 KB -