Submission #18985124


Source Code Expand

Copy
//Let's join Kaede Takagaki Fan Club !!
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
//#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
#define all(x) x.begin(),x.end()
template<class T>
void dmp(T a){
	rep(i,a.size()) cout << a[i] << " ";
	cout << endl;
}
template<class T>
bool chmax(T&a, T b){
	if(a < b){
		a = b;
		return 1;
	}
	return 0;
}
template<class T>
bool chmin(T&a, T b){
	if(a > b){
		a = b;
		return 1;
	}
	return 0;
}
template<class T>
void g(T &a){
	cin >> a;
}
template<class T>
void o(const T &a,bool space=false){
	cout << a << (space?' ':'\n');
}
//ios::sync_with_stdio(false);
const ll mod = 1000000007;//998244353
template<class T>
void add(T&a,T b){
	a+=b;
	if(a >= mod) a-=mod;
}

int n;
ll dp[2][2505][2505], ans;
vector<P>vec;
ll solve(int L, int R){
	rep(fix, 2) rep(a, 2505) rep(b, 2505) dp[fix][a][b] = 5e18;
	dp[0][0][0] = 0;
	rep(i, vec.size()){
		rep(fix, 2) rep(a, L+1) {
			if(fix + a > i) continue;
			if(i - (fix + a) > R) continue;
			int b = i - (fix + a);
			if(dp[fix][a][b] > 4e18) continue;
			if(fix == 0){
				chmin(dp[1][a][b], dp[0][a][b] + 1LL*vec[i].fi*L + 1LL*vec[i].sc*R);
			}
			if(a < L){
				chmin(dp[fix][a+1][b], dp[fix][a][b] + 1LL*(L-1-a)*(vec[i].fi+vec[i].sc) + vec[i].sc);
			}
			if(b < R){
				chmin(dp[fix][a][b+1], dp[fix][a][b] + 1LL*(R-1-b)*(vec[i].fi+vec[i].sc) + vec[i].fi);
			}
		}
	}
	return dp[1][L][R];
}
int main(){
	cin >> n;
	rep(i, n){
		int a, b; cin >> a >> b;
		vec.pb(mp(a, b));
	}
	sort(vec.begin(), vec.end(), [](P a, P b){
		return a.sc + a.fi < b.sc + b.fi;
	});
	int m = (n-1)/2;
	ans = 5e18;
	chmin(ans, solve(m, n-1-m));
	chmin(ans, solve(n-1-m, m));
	cout << ans << '\n';
}

Submission Info

Submission Time
Task F - Intervals
User IH19980412
Language C++ (GCC 9.2.1)
Score 1000
Code Size 2392 Byte
Status AC
Exec Time 403 ms
Memory 101780 KB

Compile Error

./Main.cpp: In function ‘ll solve(int, int)’:
./Main.cpp:19:31: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::vector<std::pair<int, int> >::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
   19 | #define rep(i,x) for(int i=0;i<x;i++)
......
   69 |  rep(i, vec.size()){
      |      ~~~~~~~~~~~~~             
./Main.cpp:69:2: note: in expansion of macro ‘rep’
   69 |  rep(i, vec.size()){
      |  ^~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 1000 / 1000
Status
AC × 2
AC × 45
Set Name Test Cases
Sample example0.txt, example1.txt
All 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, 024.txt, 025.txt, 026.txt, 027.txt, 028.txt, 029.txt, 030.txt, 031.txt, 032.txt, 033.txt, 034.txt, 035.txt, 036.txt, 037.txt, 038.txt, 039.txt, 040.txt, 041.txt, 042.txt, example0.txt, example1.txt
Case Name Status Exec Time Memory
000.txt AC 391 ms 101712 KB
001.txt AC 122 ms 101672 KB
002.txt AC 387 ms 101664 KB
003.txt AC 306 ms 101664 KB
004.txt AC 384 ms 101684 KB
005.txt AC 184 ms 101748 KB
006.txt AC 387 ms 101776 KB
007.txt AC 214 ms 101668 KB
008.txt AC 387 ms 101684 KB
009.txt AC 98 ms 101640 KB
010.txt AC 388 ms 101780 KB
011.txt AC 196 ms 101672 KB
012.txt AC 385 ms 101768 KB
013.txt AC 93 ms 101688 KB
014.txt AC 388 ms 101540 KB
015.txt AC 122 ms 101612 KB
016.txt AC 387 ms 101540 KB
017.txt AC 298 ms 101724 KB
018.txt AC 388 ms 101668 KB
019.txt AC 209 ms 101624 KB
020.txt AC 72 ms 101560 KB
021.txt AC 71 ms 101636 KB
022.txt AC 403 ms 101680 KB
023.txt AC 385 ms 101600 KB
024.txt AC 386 ms 101664 KB
025.txt AC 385 ms 101668 KB
026.txt AC 386 ms 101684 KB
027.txt AC 388 ms 101664 KB
028.txt AC 389 ms 101596 KB
029.txt AC 387 ms 101668 KB
030.txt AC 388 ms 101668 KB
031.txt AC 386 ms 101664 KB
032.txt AC 389 ms 101540 KB
033.txt AC 388 ms 101668 KB
034.txt AC 385 ms 101680 KB
035.txt AC 388 ms 101732 KB
036.txt AC 389 ms 101544 KB
037.txt AC 383 ms 101600 KB
038.txt AC 385 ms 101596 KB
039.txt AC 387 ms 101668 KB
040.txt AC 389 ms 101596 KB
041.txt AC 387 ms 101712 KB
042.txt AC 385 ms 101544 KB
example0.txt AC 73 ms 101560 KB
example1.txt AC 77 ms 101612 KB