Submission #554633

# Submission time Handle Problem Language Result Execution time Memory
554633 2022-04-29T01:49:08 Z cheetose Pinball (JOI14_pinball) C++17
0 / 100
1 ms 340 KB
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define y0 y12
#define y1 y22
#define INF 987654321987654321
#define PI 3.141592653589793238462643383279502884
#define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
#define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
#define MEM0(a) memset((a),0,sizeof(a))
#define MEM_1(a) memset((a),-1,sizeof(a))
#define ALL(a) a.begin(),a.end()
#define COMPRESS(a) sort(ALL(a));a.resize(unique(ALL(a))-a.begin())
#define SYNC ios_base::sync_with_stdio(false);cin.tie(0)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef double db;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef pair<ld, ld> Pd;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<ld> Vd;
typedef vector<Pi> VPi;
typedef vector<Pll> VPll;
typedef vector<Pd> VPd;
typedef tuple<int, int, int> iii;
typedef tuple<int, int, int, int> iiii;
typedef tuple<ll, ll, ll> LLL;
typedef vector<iii> Viii;
typedef vector<LLL> VLLL;
typedef complex<double> base;
const int MOD = 998244353;
ll POW(ll a, ll b, ll MMM = MOD) { ll ret = 1; for (; b; b >>= 1, a = (a*a) % MMM)if (b & 1)ret = (ret*a) % MMM; return ret; }
int dx[] = { 0,1,0,-1,1,1,-1,-1 }, dy[] = { 1,0,-1,0,1,-1,1,-1 };
int ddx[] = { -1,-2,1,-2,2,-1,2,1 }, ddy[] = { -2,-1,-2,1,-1,2,1,2 };

ll tree1[1048576],tree2[1048576];
void init(ll *tree,int node,int S,int E){
	tree[node]=INF;
	if(S==E)return;
	int L=node<<1,R=L|1,M=S+E>>1;
	init(tree,L,S,M);
	init(tree,R,M+1,E);
}
void upd(ll *tree,int node,int S,int E,int k,ll dif){
	if(S==E){
		tree[node]=min(tree[node],dif);
		return;
	}
	int L=node<<1,R=L|1,M=S+E>>1;
	if(k<=M)upd(tree,L,S,M,k,dif);
	else upd(tree,R,M+1,E,k,dif);
	tree[node]=min(tree[L],tree[R]);
}

ll find(ll *tree,int node,int S,int E,int i,int j){
	if(i>E || j<S)return INF;
	if(i<=S && j>=E)return tree[node];
	int L=node<<1,R=L|1,M=S+E>>1;
	return min(find(tree,L,S,M,i,j),find(tree,R,M+1,E,i,j));
}
int a[100000],b[100000],c[100000],d[100000];
int main(){
	int n;
	scanf("%d%*d",&n);
	Vi vv;
	fup(i,0,n-1,1){
		scanf("%d%d%d%d",a+i,b+i,c+i,d+i);
		vv.pb(a[i]);vv.pb(b[i]);vv.pb(c[i]);
	}
	COMPRESS(vv);
	fup(i,0,n-1,1)a[i]=lower_bound(ALL(vv),a[i])-vv.begin(),b[i]=lower_bound(ALL(vv),b[i])-vv.begin(),c[i]=lower_bound(ALL(vv),c[i])-vv.begin();
	int N=vv.size();
	init(tree1,1,0,N-1);init(tree2,1,0,N-1);
	upd(tree1,1,0,N-1,0,0);upd(tree2,1,0,N-1,N-1,0);
	ll ans=INF;
	fup(i,0,n-1,1){
		ll t1=find(tree1,1,0,N-1,a[i],b[i]),t2=find(tree2,1,0,N-1,a[i],b[i]);
		ans=min(ans,t1+t2+d[i]);
		upd(tree1,1,0,N-1,c[i],t1+d[i]);
		upd(tree2,1,0,N-1,c[i],t2+d[i]);
	}
	printf("%lld\n",ans==INF?-1:ans);
}

Compilation message

pinball.cpp: In function 'void init(ll*, int, int, int)':
pinball.cpp:47:25: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   47 |  int L=node<<1,R=L|1,M=S+E>>1;
      |                        ~^~
pinball.cpp: In function 'void upd(ll*, int, int, int, int, ll)':
pinball.cpp:56:25: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   56 |  int L=node<<1,R=L|1,M=S+E>>1;
      |                        ~^~
pinball.cpp: In function 'll find(ll*, int, int, int, int, int)':
pinball.cpp:65:25: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   65 |  int L=node<<1,R=L|1,M=S+E>>1;
      |                        ~^~
pinball.cpp: In function 'int main()':
pinball.cpp:10:30: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
      |                              ^
pinball.cpp:73:2: note: in expansion of macro 'fup'
   73 |  fup(i,0,n-1,1){
      |  ^~~
pinball.cpp:10:30: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
      |                              ^
pinball.cpp:78:2: note: in expansion of macro 'fup'
   78 |  fup(i,0,n-1,1)a[i]=lower_bound(ALL(vv),a[i])-vv.begin(),b[i]=lower_bound(ALL(vv),b[i])-vv.begin(),c[i]=lower_bound(ALL(vv),c[i])-vv.begin();
      |  ^~~
pinball.cpp:10:30: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
      |                              ^
pinball.cpp:83:2: note: in expansion of macro 'fup'
   83 |  fup(i,0,n-1,1){
      |  ^~~
pinball.cpp:71:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   71 |  scanf("%d%*d",&n);
      |  ~~~~~^~~~~~~~~~~~
pinball.cpp:74:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   74 |   scanf("%d%d%d%d",a+i,b+i,c+i,d+i);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Incorrect 1 ms 340 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Incorrect 1 ms 340 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Incorrect 1 ms 340 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Incorrect 1 ms 340 KB Output isn't correct
8 Halted 0 ms 0 KB -