Submission #46315622


Source Code Expand

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

#define rep(i,n) for(ll i=0;i<n;++i)
#define rrep(i,n) for(ll i=n-1;i>=0;--i)
#define FOR(i,s,e) for(ll i=s;i<=e;++i)
#define FFOR(i,s,e) for(ll i=s;i>=e;--i)

#define yesno(flg) if(flg){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}
#define ALL(a) (a).begin(),(a).end()
#define mp make_pair
#define pb push_back
#define vl vector<ll>
#define vs vector<string>
#define so(a) sort(a.begin(),a.end())

#define fi first
#define se second
#define print(a) cout<<a<<endl
#define ssize(a) (ll)(a.size())

#define MAX_N 1002
#define i197 1000000007
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

typedef pair<int,int> Pi;
typedef pair<ll, ll> P2;
typedef pair<P2,ll> P3;
typedef pair<P2,P2> P4;

const ll INF=1000000000000000001;

int main(){

	ios::sync_with_stdio(0);
	cin.tie(0);

	ll n;
	cin>>n;

	map<ll,int> ma;
	vector<P2> sc(n);
	rep(i,n){
		ll s2,c2;
		cin>>s2>>c2;
		sc[i]=P2(s2,c2);
		ma[s2]=c2;
	}
	so(sc);
	ll ans=0;
	rep(i,n){
		ll s2=sc[i].fi;
		ll c2=ma[s2];
		while(c2>1){
			if(s2*2>sc[n-1].fi){
				while(c2>0){
					ans+=c2%2;
					c2/=2;
				}
			}else{
				if(ma[s2*2]){
					ma[s2*2]+=c2/2;
					ans+=c2%2;
					c2=0;
				}else{
					s2*=2;
					ans+=c2%2;
					c2/=2;
				}
			}
		}
		ans+=c2;
	}

	print(ans);


	return 0;
}








Submission Info

Submission Time
Task D - Merge Slimes
User akarinkof
Language C++ 20 (gcc 12.2)
Score 425
Code Size 1537 Byte
Status AC
Exec Time 118 ms
Memory 24568 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 425 / 425
Status
AC × 3
AC × 33
Set Name Test Cases
Sample example_00.txt, example_01.txt, example_02.txt
All example_00.txt, example_01.txt, example_02.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, hand_06.txt, hand_07.txt, hand_08.txt, hand_09.txt, hand_10.txt, hand_11.txt, hand_12.txt, hand_13.txt, hand_14.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt
Case Name Status Exec Time Memory
example_00.txt AC 1 ms 3504 KiB
example_01.txt AC 1 ms 3404 KiB
example_02.txt AC 1 ms 3636 KiB
hand_00.txt AC 65 ms 11108 KiB
hand_01.txt AC 61 ms 11100 KiB
hand_02.txt AC 76 ms 17068 KiB
hand_03.txt AC 52 ms 10960 KiB
hand_04.txt AC 64 ms 11100 KiB
hand_05.txt AC 1 ms 3572 KiB
hand_06.txt AC 1 ms 3516 KiB
hand_07.txt AC 61 ms 11096 KiB
hand_08.txt AC 1 ms 3436 KiB
hand_09.txt AC 1 ms 3636 KiB
hand_10.txt AC 66 ms 10948 KiB
hand_11.txt AC 61 ms 11040 KiB
hand_12.txt AC 76 ms 17168 KiB
hand_13.txt AC 53 ms 10916 KiB
hand_14.txt AC 64 ms 10936 KiB
random_00.txt AC 84 ms 15092 KiB
random_01.txt AC 95 ms 18352 KiB
random_02.txt AC 104 ms 20732 KiB
random_03.txt AC 110 ms 22460 KiB
random_04.txt AC 115 ms 23632 KiB
random_05.txt AC 118 ms 24568 KiB
random_06.txt AC 17 ms 6280 KiB
random_07.txt AC 14 ms 5928 KiB
random_08.txt AC 77 ms 17044 KiB
random_09.txt AC 76 ms 17372 KiB
random_10.txt AC 76 ms 17108 KiB
random_11.txt AC 76 ms 17104 KiB
random_12.txt AC 76 ms 17072 KiB
random_13.txt AC 75 ms 17032 KiB
random_14.txt AC 75 ms 17112 KiB