Submission #1175912
Source Code Expand
#include <bits/stdc++.h>
#include <unistd.h>
using namespace std;
//make_tuple emplace_back next_permutation push_back make_pair second first setprecision
#if MYDEBUG
#include "lib/cp_debug.h"
#else
#define DBG(...) ;
#endif
#define pops(x) __builtin_popcount(x)
using LL = long long;
constexpr LL LINF=334ll<<53;
constexpr int INF=15<<26;
constexpr LL MOD=1E9+7;
constexpr double eps=1e-7;
struct Action{
string str;
vector<int> ints;
};
int change_cnt;
vector<int> sold(10),came(10);
struct Problem{
const int turn= 1000;
const int capacity_comb=24310;
const vector<int> ttttt={1000,100,10,1};
const int lb=26;
const int width=5;
const int cf_criterion=40;
const double score_per_turn=70.0;
int n,d,t;
vector<vector<int>> index;
vector<vector<vector<int>>> graph;
vector<vector<vector<short>>> times;
unordered_map<LL,int> mp;
vector<int> cap,now,perm;
queue<Action> to_do;
Problem(LL n):
n(n),
graph(capacity_comb,vector<vector<int>>(8)),
times (capacity_comb,vector<vector<short>>(51,vector<short>())),
cap(n),
now(n),
perm(n){};
void solve(){
bool searched=false;
precalc();
for(int i=0; i<turn; ++i){
input();
if(!to_do.empty()){
act();
continue;
}
LL tank_state=mp[get_tank_state(cap)];
int filled= get_bit(cap, now);
vector<pair<int,int>> tanks_select;
for(auto i : times[tank_state][d]){
tanks_select.emplace_back(pops(i-(i&filled)),i);
}
sort(tanks_select.begin(),tanks_select.end());
auto it=lower_bound(tanks_select.begin(),tanks_select.end(),make_pair(t,0));
if(d>=lb && it>tanks_select.begin()){ //詰めて売る
vector<int> to_sell={0};
auto nxt=lower_bound(tanks_select.begin(),tanks_select.end(),make_pair((it-1)->first,0));
int mask=nxt->second-(nxt->second&filled);
DBG(mask,filled,nxt->second)
for(int b=0; b<8; ++b){
if(mask&(1<<b))to_do.push({"fill",{perm[b]}});
if(nxt->second&(1<<b)){
to_sell[0]++;
to_sell.push_back(perm[b]);
}
}
//暇ならfillしておく
for(int b=7; b>=0; --b){
if (!(filled&(1<<b))&& !(mask&(1<<b)) && (int)to_do.size()<t-1){
to_do.push({"fill",{perm[b]}});
}
}
to_do.push({"sell",to_sell});
}else if(d>=lb){
pair<int,int>success_rate;
if(!searched){
success_rate=change_success_rate(tank_state,filled);
DBG(success_rate)
}
if(!searched && (double)success_rate.first/1000*d*d/t>score_per_turn){
to_do.push({"change",{perm[success_rate.second]}});
}else{
searched=true;
if(accumulate(cap.begin(),cap.end(),0)<cf_criterion){
to_do.push({"change",{perm[0]}});
}else{
//暇ならfillしておく
for(int b=7; b>=0; --b){
if(!(filled&(1<<b))){
to_do.push({"fill",{perm[b]}});
break;
}
if(b==0){
if(t==1)to_do.push({"change",{perm[0]}});
else to_do.push({"pass",{}});
searched=false;
}
}
}
if(t==1)searched=false;
}
}else{ //安いので売らない
for(int b=7; b>=0; --b){
if(!(filled&(1<<b))){
to_do.push({"fill",{perm[b]}});
break;
}
if(b==0){
if(t==1)to_do.push({"change",{perm[0]}});
else to_do.push({"pass",{}});
}
}
//if(t==1)to_do.push({"change",{perm[0]}});
//else to_do.push({"pass",{}});
}
#if MYDEBUG
usleep(20000);
cerr<<flush;
#endif
act();
}
}
LL get_tank_state(vector<int> &c){
LL ret=0;
for(int i=0; i<8; ++i){
ret+=c[i];
ret<<=4;
}
return ret;
}
int get_bit(vector<int> &c, vector<int> &a){
int ret=0;
for(int i=0; i<8; ++i){
if(c[i]==a[i])ret+=(1<<i);
}
return ret;
}
pair<int,int> change_success_rate(int state, int fill_mask,int depth=1){
int maxi=0,ret=0;
for(int i=0; i<width; ++i){
if(i&&(index[state][i]==index[state][i-1])) continue;
vector<pair<int,int>> now(8),tmp(8);
for(int j=0; j<8; ++j){
now[j].first=index[state][j];
now[j].second=((fill_mask>>j)&1);
}
int cnt=0;
now[i].second=0;
for(int draw=1; draw<=10; ++draw){
tmp=now;
tmp[i].first=draw;
sort(tmp.begin(),tmp.end());
vector<int> nxt(8);
int new_mask=0;
for(int j=0; j<8; ++j){
nxt[j]=tmp[j].first;
new_mask+=(tmp[j].second<<j);
}
int new_state=mp[get_tank_state(nxt)];
bool f=false;
for(auto v: times[new_state][d]){
if(pops(v-(v&new_mask))<t-depth){
cnt+=ttttt[depth];
f=true;
break;
}
}
if(depth<=2&&!f){
cnt+=change_success_rate(new_state,new_mask,depth+1).first;
}
}
if(cnt>ret)maxi=i,ret=cnt;
}
return {ret,maxi};
}
void input(){
cin >> d >> t;
vector<vector<int>> p(8,vector<int>(3));
for(int i=0; i<n; ++i){
cin >> p[i][0];
}
for(int i=0; i<n; ++i){
cin >> p[i][1];
p[i][2]=i+1;
}
sort(p.begin(),p.end());
for(int i=0; i<n; ++i){
cap[i]=p[i][0];
now[i]=p[i][1];
perm[i]=p[i][2];
}
}
void precalc(){
vector<int> loop(8);
int cnt=0;
for(loop[0]=1; loop[0]<=10; ++loop[0]){
for(loop[1]=loop[0]; loop[1]<=10; ++loop[1]){
for(loop[2]=loop[1]; loop[2]<=10; ++loop[2]){
for(loop[3]=loop[2]; loop[3]<=10; ++loop[3]){
for(loop[4]=loop[3]; loop[4]<=10; ++loop[4]){
for(loop[5]=loop[4]; loop[5]<=10; ++loop[5]){
for(loop[6]=loop[5]; loop[6]<=10; ++loop[6]){
for(loop[7]=loop[6]; loop[7]<=10; ++loop[7]){
LL tmp=0;
for(int i=0; i<8; ++i){
tmp+=loop[i];
tmp<<=4;
}
index.push_back(loop);
mp[tmp]=cnt;
bf(loop,times[cnt]);
cnt++;
}
}
}
}
}
}
}
}
for(int i=0; i<capacity_comb; ++i){
vector<int> tmp;
for(int j=0; j<n; ++j){
for(int k=1;k<=10; ++k){
tmp=index[i];
tmp[j]=k;
sort(tmp.begin(),tmp.end());
int nxt=mp[get_tank_state(tmp)];
graph[i][j].push_back(nxt);
}
}
}
}
void bf(vector<int>&c, vector<vector<short>> &t_table){
for(int fillbit=1; fillbit<=255; ++fillbit){
int amount=0;
for(int b=0; b<8; ++b){
if((fillbit>>b)&1){
amount+=c[b];
}
}
if(lb<=amount && amount<=50){
t_table[amount].push_back(fillbit);
}
}
for(int i=lb; i<=50; ++i){
sort(t_table[i].begin(),t_table[i].end());
}
}
void act(){
if(t==1 || to_do.front().str=="pass" || to_do.front().str =="sell"){
came[(d-1)/5]++;
if(to_do.front().str =="sell")sold[(d-1)/5]++;
}
if(to_do.front().str =="change")change_cnt++;
cout << to_do.front().str;
for(auto i : to_do.front().ints)cout << ' ' <<i;
cout << endl;
to_do.pop();
}
};
int main(){
//cin.tie(0);
//ios_base::sync_with_stdio(false);
long long n=8;
Problem p(n);
p.solve();
cerr<<change_cnt<<"\n";
for(int i=0; i<10; ++i){
cerr<<i<<' '<<came[i]<<' '<<sold[i]<<endl;
}
return 0;
}
Submission Info
Submission Time |
|
Task |
A - 石油王Xの憂鬱 |
User |
Hoi_koro |
Language |
C++14 (GCC 5.4.1) |
Score |
7477593 |
Code Size |
9920 Byte |
Status |
AC |
Exec Time |
1368 ms |
Memory |
69000 KB |
Judge Result
Set Name |
test_01 |
test_02 |
test_03 |
test_04 |
test_05 |
test_06 |
test_07 |
test_08 |
test_09 |
test_10 |
test_11 |
test_12 |
test_13 |
test_14 |
test_15 |
test_16 |
test_17 |
test_18 |
test_19 |
test_20 |
test_21 |
test_22 |
test_23 |
test_24 |
test_25 |
test_26 |
test_27 |
test_28 |
test_29 |
test_30 |
test_31 |
test_32 |
test_33 |
test_34 |
test_35 |
test_36 |
test_37 |
test_38 |
test_39 |
test_40 |
test_41 |
test_42 |
test_43 |
test_44 |
test_45 |
test_46 |
test_47 |
test_48 |
test_49 |
test_50 |
Score / Max Score |
146614 / 417500 |
151915 / 417500 |
153599 / 417500 |
156350 / 417500 |
138310 / 417500 |
150102 / 417500 |
158096 / 417500 |
143658 / 417500 |
154654 / 417500 |
157072 / 417500 |
160392 / 417500 |
144771 / 417500 |
156272 / 417500 |
153961 / 417500 |
141173 / 417500 |
154213 / 417500 |
147688 / 417500 |
150482 / 417500 |
151177 / 417500 |
147629 / 417500 |
159097 / 417500 |
156378 / 417500 |
148604 / 417500 |
145281 / 417500 |
156947 / 417500 |
147706 / 417500 |
149380 / 417500 |
149981 / 417500 |
149337 / 417500 |
152123 / 417500 |
146319 / 417500 |
144357 / 417500 |
144057 / 417500 |
148052 / 417500 |
151395 / 417500 |
144418 / 417500 |
148309 / 417500 |
146416 / 417500 |
151609 / 417500 |
149603 / 417500 |
144309 / 417500 |
145089 / 417500 |
148701 / 417500 |
146273 / 417500 |
151896 / 417500 |
142798 / 417500 |
141716 / 417500 |
146743 / 417500 |
149902 / 417500 |
152669 / 417500 |
Status |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Set Name |
Test Cases |
test_01 |
subtask_01_01.txt |
test_02 |
subtask_01_02.txt |
test_03 |
subtask_01_03.txt |
test_04 |
subtask_01_04.txt |
test_05 |
subtask_01_05.txt |
test_06 |
subtask_01_06.txt |
test_07 |
subtask_01_07.txt |
test_08 |
subtask_01_08.txt |
test_09 |
subtask_01_09.txt |
test_10 |
subtask_01_10.txt |
test_11 |
subtask_01_11.txt |
test_12 |
subtask_01_12.txt |
test_13 |
subtask_01_13.txt |
test_14 |
subtask_01_14.txt |
test_15 |
subtask_01_15.txt |
test_16 |
subtask_01_16.txt |
test_17 |
subtask_01_17.txt |
test_18 |
subtask_01_18.txt |
test_19 |
subtask_01_19.txt |
test_20 |
subtask_01_20.txt |
test_21 |
subtask_01_21.txt |
test_22 |
subtask_01_22.txt |
test_23 |
subtask_01_23.txt |
test_24 |
subtask_01_24.txt |
test_25 |
subtask_01_25.txt |
test_26 |
subtask_01_26.txt |
test_27 |
subtask_01_27.txt |
test_28 |
subtask_01_28.txt |
test_29 |
subtask_01_29.txt |
test_30 |
subtask_01_30.txt |
test_31 |
subtask_01_31.txt |
test_32 |
subtask_01_32.txt |
test_33 |
subtask_01_33.txt |
test_34 |
subtask_01_34.txt |
test_35 |
subtask_01_35.txt |
test_36 |
subtask_01_36.txt |
test_37 |
subtask_01_37.txt |
test_38 |
subtask_01_38.txt |
test_39 |
subtask_01_39.txt |
test_40 |
subtask_01_40.txt |
test_41 |
subtask_01_41.txt |
test_42 |
subtask_01_42.txt |
test_43 |
subtask_01_43.txt |
test_44 |
subtask_01_44.txt |
test_45 |
subtask_01_45.txt |
test_46 |
subtask_01_46.txt |
test_47 |
subtask_01_47.txt |
test_48 |
subtask_01_48.txt |
test_49 |
subtask_01_49.txt |
test_50 |
subtask_01_50.txt |
Case Name |
Status |
Exec Time |
Memory |
subtask_01_01.txt |
AC |
975 ms |
66948 KB |
subtask_01_02.txt |
AC |
1188 ms |
66952 KB |
subtask_01_03.txt |
AC |
1246 ms |
66952 KB |
subtask_01_04.txt |
AC |
1348 ms |
66952 KB |
subtask_01_05.txt |
AC |
1285 ms |
66952 KB |
subtask_01_06.txt |
AC |
1158 ms |
66952 KB |
subtask_01_07.txt |
AC |
1160 ms |
66952 KB |
subtask_01_08.txt |
AC |
1226 ms |
66952 KB |
subtask_01_09.txt |
AC |
1064 ms |
66952 KB |
subtask_01_10.txt |
AC |
1368 ms |
66952 KB |
subtask_01_11.txt |
AC |
1096 ms |
66952 KB |
subtask_01_12.txt |
AC |
1194 ms |
66952 KB |
subtask_01_13.txt |
AC |
1242 ms |
66952 KB |
subtask_01_14.txt |
AC |
1264 ms |
66952 KB |
subtask_01_15.txt |
AC |
1165 ms |
66952 KB |
subtask_01_16.txt |
AC |
1086 ms |
66952 KB |
subtask_01_17.txt |
AC |
1114 ms |
66956 KB |
subtask_01_18.txt |
AC |
1157 ms |
66952 KB |
subtask_01_19.txt |
AC |
1052 ms |
66956 KB |
subtask_01_20.txt |
AC |
1106 ms |
66952 KB |
subtask_01_21.txt |
AC |
1118 ms |
66956 KB |
subtask_01_22.txt |
AC |
1195 ms |
66956 KB |
subtask_01_23.txt |
AC |
1118 ms |
66952 KB |
subtask_01_24.txt |
AC |
1260 ms |
66952 KB |
subtask_01_25.txt |
AC |
1138 ms |
69000 KB |
subtask_01_26.txt |
AC |
1143 ms |
66952 KB |
subtask_01_27.txt |
AC |
1086 ms |
66952 KB |
subtask_01_28.txt |
AC |
942 ms |
66956 KB |
subtask_01_29.txt |
AC |
1037 ms |
66956 KB |
subtask_01_30.txt |
AC |
1137 ms |
66952 KB |
subtask_01_31.txt |
AC |
1015 ms |
66952 KB |
subtask_01_32.txt |
AC |
1280 ms |
66952 KB |
subtask_01_33.txt |
AC |
1170 ms |
66952 KB |
subtask_01_34.txt |
AC |
1204 ms |
66952 KB |
subtask_01_35.txt |
AC |
1117 ms |
66952 KB |
subtask_01_36.txt |
AC |
1220 ms |
66952 KB |
subtask_01_37.txt |
AC |
1156 ms |
66952 KB |
subtask_01_38.txt |
AC |
1139 ms |
66952 KB |
subtask_01_39.txt |
AC |
1339 ms |
66952 KB |
subtask_01_40.txt |
AC |
1213 ms |
66948 KB |
subtask_01_41.txt |
AC |
1169 ms |
66956 KB |
subtask_01_42.txt |
AC |
1062 ms |
66952 KB |
subtask_01_43.txt |
AC |
1127 ms |
66952 KB |
subtask_01_44.txt |
AC |
1120 ms |
66952 KB |
subtask_01_45.txt |
AC |
1117 ms |
66952 KB |
subtask_01_46.txt |
AC |
1105 ms |
66952 KB |
subtask_01_47.txt |
AC |
1293 ms |
66948 KB |
subtask_01_48.txt |
AC |
1320 ms |
66952 KB |
subtask_01_49.txt |
AC |
1104 ms |
66952 KB |
subtask_01_50.txt |
AC |
1108 ms |
66952 KB |