Submission #889217

# Submission time Handle Problem Language Result Execution time Memory
889217 2023-12-19T08:03:21 Z Minbaev Pinball (JOI14_pinball) C++17
11 / 100
3 ms 348 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimize("Ofast,unroll-loops")
#define pii pair<int,int>
using namespace __gnu_pbds;
using namespace std;
#define pb push_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define int long long
#define f first
#define s second
#define pii pair<int,int>
template<class T>bool umax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<class T>bool umin(T &a,T b){if(b<a){a=b;return true;}return false;}
typedef tree<int, null_type, less_equal<int>, rb_tree_tag,
	tree_order_statistics_node_update> ordered_set;
const int mod= 1e17 +7;
const int N=1e5*4;

int binpow (int a, int n) {
	if (n == 0)
		return 1;
	if (n % 2 == 1)
		return binpow (a, n-1) * a;
	else {
		int b = binpow (a, n/2);
		return b * b;
	}
}

void solve(){
	int n,m,k;

	cin>>n>>m;
	vector<pair<pii,pii>>v(n);
	for(int i = 0;i<n;i++){
		cin>>v[i].f.f>>v[i].f.s>>v[i].s.f>>v[i].s.s;
	}
	
	int ans = mod;
	
	for(int mask = 0;mask<(1<<n);mask++){
		set<pii>st;
		int sum = 0;
		st.insert({1,m});
		for(int i = 0;i<n;i++){
			if(((mask>>i)&1)==0)continue;
			sum += v[i].s.s;
			vector<pii>del,add;
			int l = v[i].f.f;
			int r = v[i].f.s;
			add.pb({v[i].s.f,v[i].s.f});
			
			for(auto [l1,r1]:st){
				
				 if(l1<=l&&r<=r1){
					del.pb({l1,r1});
					if(l!=l1)add.pb({l1,l-1});
					if(r!=r1)add.pb({r+1,r1});
				}
				else if(l1 <= l && r1 <= r && l <= r1){
					del.pb({l1,r1});
					if(l1!=l)add.pb({l1,l-1});
				}
				else if(r1 >= r && l1 >= l && l1 <= r){
					del.pb({l1,r1});
					if(r1!=r)add.pb({r+1,r1});
				}
				else if(l<=l1&&r1<=r){
					del.pb({l1,r1});
				}
				
			}
			for(auto to:del)st.erase(st.find(to));
			for(auto to:add)st.insert(to);
		}
		
		if(st.size()==1&&sum>0){
			umin(ans,sum);
		
			
		}
	}
	if(ans==mod)ans=-1;
	cout<<ans<<"\n";







}

 signed main()
{
//	freopen("seq.in", "r", stdin);
//  freopen("seq.out", "w", stdout);
	ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
	int cnt=0;
	int tt=1;//cin>>tt;
	while(tt--)solve();

}

Compilation message

pinball.cpp: In function 'void solve()':
pinball.cpp:35:10: warning: unused variable 'k' [-Wunused-variable]
   35 |  int n,m,k;
      |          ^
pinball.cpp: In function 'int main()':
pinball.cpp:103:6: warning: unused variable 'cnt' [-Wunused-variable]
  103 |  int cnt=0;
      |      ^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 2 ms 348 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 3 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 2 ms 348 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 3 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Incorrect 1 ms 344 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 2 ms 348 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 3 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Incorrect 1 ms 344 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 2 ms 348 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 3 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Incorrect 1 ms 344 KB Output isn't correct
10 Halted 0 ms 0 KB -