Submission #524418

# Submission time Handle Problem Language Result Execution time Memory
524418 2022-02-09T07:38:35 Z iskhakkutbilim Table Tennis (info1cup20_tabletennis) C++14
49 / 100
3000 ms 4352 KB
// Author: Tazhibaev Iskhak
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 

using namespace __gnu_pbds;
using namespace std;

typedef tree<pair<int, int> ,null_type,less< pair<int, int> >,rb_tree_tag,
	tree_order_statistics_node_update> ordered_set;
const long double pi = acos((long double) - 1.0);
const double eps = (double)1e-9;
const int INF = 1e9 + 7;
    #define ff         first
    #define ss         second
    #define ll         long long
    #define ld		   long double
    #define pb         push_back
void usaco( string filename){
  freopen((filename+".in").c_str(), "r", stdin);
  freopen((filename+".out").c_str(), "w", stdout);
}




main(){
	 ios_base::sync_with_stdio(false);
	 cin.tie(nullptr); cout.tie(nullptr);
	 int n, k; cin >> n >> k;
	 vector<int> a(n + k);
	 for(int i = 0;i < n + k; i++){
	 	cin >> a[i];
	 }
	 
	 function <bool(vector<int>) > good = [&](vector<int> s){
	 	for(int i = 0;i < n; i++){
	 		int j = i + 1;
	 		if(j >= n or (n - i - 1) < 0 or (n - j - 1) < 0) break;
	 		if(s[i] + s[n-i-1] != s[j] + s[n-j-1]) return false;
	 	}
	 	return true;
	 };
	 if(k == 1){
		 for(int i = 0;i < n + k; i++){
		 	vector<int> sub;
		 	for(int j = 0;j < n + k; j++){
		 		if(i != j) sub.push_back(a[j]);
		 	}
		 	if(good(sub)){
		 		for(auto to : sub) cout << to << " ";
		 		return 0;
		 	}
		 }
	 }else if(n + k <= 18){
	 	for(int mask = 0; mask < (1 << (n + k)); mask++){
	 		if(__builtin_popcount(mask) != n) continue;
	 		vector<int> sub;
	 		for(int i = 0;i < n + k; i++){
	 			if(mask & (1 << i)) sub.push_back(a[i]);
	 		}
	 		if(good(sub)){
	 			for(auto x : sub) cout << x << " ";
	 			return 0;
	 		}
	 	}
	 }else if(n <= 100 and k <= 100 or (n <= 150000 and k==2)){
	 	for(int i = 0; i < n + k; i++){
	 		vector<int> sub;
	 		for(int j = i;j < n + k; j++){
	 			if(sub.size() == n) break;
	 			sub.push_back(a[j]);
	 		}
	 		if(sub.size() < n) break;
	 		if(good(sub)){
		 		for(auto x : sub){
		 			cout << x << " ";
		 		}
		 		return 0;
	 		}
	 		// cout << "\n" << "------" << "\n";
	 	}
	 }else{
	 	reverse(a.begin(), a.end());
	 	for(int i = 0; i < n + k; i++){
	 		vector<int> sub;
	 		for(int j = i;j < n + k; j++){
	 			if(sub.size() == n) break;
	 			sub.push_back(a[j]);
	 		}
	 		if(sub.size() < n) break;
	 		if(good(sub)){
		 		for(auto x : sub){
		 			cout << x << " ";
		 		}
		 		return 0;
	 		}
	 		// cout << "\n" << "------" << "\n";
	 	}
	 	
	 	// map<int, int> mp;
	 	// int l = 0;
	 	// int r = n + k;
	 	// for(int i = 0;i < n+k; i++){
	 		// int j = i + 1;
	 		// if(j >= n + k) break;
	 		// if((n - i - 1) < 0 or (n - j - 1) < 0) break;
	 		// if(s[i] + s[n-i-1] != s[j] + s[n-j-1]){
// 	 			
	 		// }
	 	// }
	 	// int i_s = 0, i_e;
	 	// int j_s = 1, j_e;
	 	// while(i_e > i_s and j_e > j_s){
	 		// i_e = ((n + k) - i_s - 1);
	 		// j_e = ((n + k) - j_s - 1);
// 	 		
	 		// if(a[i_e] + a[i_s] != a[j_e] + a[j_s]){
// 	 			
	 		// }
// 	 		
	 		// i_s++;
	 		// j_s++;
	 	// }
	 	// for(int i = l;i < r; i++){
	 		// cout << a[i] << " ";
	 	// }
	 }
    return 0;
}

Compilation message

tabletennis.cpp:27:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   27 | main(){
      | ^~~~
tabletennis.cpp: In function 'int main()':
tabletennis.cpp:67:21: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   67 |   }else if(n <= 100 and k <= 100 or (n <= 150000 and k==2)){
      |            ~~~~~~~~~^~~~~~~~~~~~
tabletennis.cpp:71:20: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   71 |      if(sub.size() == n) break;
      |         ~~~~~~~~~~~^~~~
tabletennis.cpp:74:19: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   74 |     if(sub.size() < n) break;
      |        ~~~~~~~~~~~^~~
tabletennis.cpp:88:20: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   88 |      if(sub.size() == n) break;
      |         ~~~~~~~~~~~^~~~
tabletennis.cpp:91:19: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   91 |     if(sub.size() < n) break;
      |        ~~~~~~~~~~~^~~
tabletennis.cpp: In function 'void usaco(std::string)':
tabletennis.cpp:20:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |   freopen((filename+".in").c_str(), "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tabletennis.cpp:21:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |   freopen((filename+".out").c_str(), "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 8 ms 344 KB Output is correct
3 Correct 9 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 624 ms 832 KB Output is correct
2 Correct 26 ms 3124 KB Output is correct
3 Execution timed out 3063 ms 2964 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 26 ms 3880 KB Output is correct
2 Correct 27 ms 3448 KB Output is correct
3 Correct 27 ms 4352 KB Output is correct
4 Correct 26 ms 3424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Incorrect 1 ms 332 KB Output not sorted
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 31 ms 2564 KB Unexpected end of file - int32 expected
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output not sorted
2 Halted 0 ms 0 KB -