Submission #835003

# Submission time Handle Problem Language Result Execution time Memory
835003 2023-08-23T05:17:28 Z CSQ31 Sightseeing in Kyoto (JOI22_kyoto) C++17
30 / 100
484 ms 23968 KB
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define sz(a) (int)(a.size())
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
#define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false);\
debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> PII;
typedef pair<int,int> pii;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> VII;
ll gcd(ll a,ll b){if(!b)return a;else return gcd(b,a%b);}
int a[100001],b[100001];
struct pt{
	ll x,y;
	int id;
	pt(ll _x,ll _y,int _id): x(_x),y(_y),id(_id){}
	bool operator<(const pt &t) const {
		if(x * t.y == y * t.x)return id > t.id;
		return (x * t.y) < (y * t.x); 
		
	}
	//bool operator==(const pt &t) const {return x==t.x && y==t.y && id==t.id;}
};
int main()
{ 
	owo
	int n,m;
	cin>>n>>m;
	for(int i=0;i<n;i++)cin>>a[i];
	for(int i=0;i<m;i++)cin>>b[i];
	
	set<pt>h,w;
	set<int>row,col;
	
	for(int i=0;i<n;i++)row.insert(i);
	for(int i=1;i<n;i++)h.insert(pt(a[i]-a[i-1],1,i));
		
	for(int i=0;i<m;i++)col.insert(i);
	for(int i=1;i<m;i++)w.insert(pt(b[i]-b[i-1],1,i));
	ll ans = 0;
	int cx = n-1,cy = m-1;
	
	while(cx && cy){
		auto ith = h.end();
		auto itw = w.end();
		ith--;
		itw--;
		//cout<<ith->x<<" "<<ith->y<<" "<<ith->id<<" "<<ans<<'\n';
		//cout<<itw->x<<" "<<itw->y<<" "<<itw->id<<" "<<ans<<'\n';
		if(*itw < *ith){
			pt v = *ith;	
			h.erase(ith);
			auto it = row.lb(v.id);
			int lf = -1,mid,rg = -1;
			
			mid = *it;
			if(it != row.begin()){
				it--;
				lf = *it;
				it++;
			}
			it++;
			if(it != row.end())rg = *it;
			if(lf != -1)h.erase(pt(a[mid] - a[lf],mid-lf,mid));
			if(rg != -1)h.erase(pt(a[rg] - a[mid],rg-mid,rg));
			if(lf != -1 && rg != -1)h.insert(pt(a[rg] - a[lf],rg-lf,rg));
			
			row.erase(mid);
			if(cx == mid){
				auto i = row.end();
				i--;
				ans+=(cx - *i)  * 1LL * b[cy];
				cx = *i;
			}
		
		}else{
			pt v = *itw;
			w.erase(itw);
			auto it = col.lb(v.id);
			int lf = -1,mid,rg = -1;
			
			mid = *it;
			if(it != col.begin()){
				it--;
				lf = *it;
				it++;
			}
			it++;
			if(it != col.end())rg = *it;
			if(lf != -1)w.erase(pt(b[mid] - b[lf],mid-lf,mid));
			if(rg != -1)w.erase(pt(b[rg] - b[mid],rg-mid,rg));
			if(lf != -1 && rg != -1)w.insert(pt(b[rg] - b[lf],rg-lf,rg));
			
			col.erase(mid);
			if(cy == mid){
				auto i = col.end();
				i--;
				ans+=(cy - *i)  * 1LL * a[cx];
				cy = *i;
			}
			//cout<<v.x<<" "<<v.y<<" "<<v.id<<" "<<ans<<'\n';
			//cout<<cx<<" "<<cy<<'\n';
		}
	}
	ans+=cy*a[0];
	ans+=cx*b[0];
	cout<<ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 328 KB Output is correct
4 Incorrect 1 ms 340 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 117 ms 9912 KB Output is correct
5 Correct 70 ms 9292 KB Output is correct
6 Correct 40 ms 4180 KB Output is correct
7 Correct 484 ms 23824 KB Output is correct
8 Correct 454 ms 23680 KB Output is correct
9 Correct 457 ms 23788 KB Output is correct
10 Correct 464 ms 23912 KB Output is correct
11 Correct 140 ms 23712 KB Output is correct
12 Correct 436 ms 23792 KB Output is correct
13 Correct 451 ms 23792 KB Output is correct
14 Correct 246 ms 23780 KB Output is correct
15 Correct 151 ms 23968 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 340 KB Output is correct
24 Correct 0 ms 336 KB Output is correct
25 Correct 0 ms 340 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 328 KB Output is correct
4 Incorrect 1 ms 340 KB Output isn't correct
5 Halted 0 ms 0 KB -