結果
問題 | No.1739 Princess vs. Dragoness (& AoE) |
ユーザー |
|
提出日時 | 2025-02-25 10:06:52 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 646 ms / 3,000 ms |
コード長 | 1,229 bytes |
コンパイル時間 | 983 ms |
コンパイル使用メモリ | 75,248 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2025-02-25 10:07:07 |
合計ジャッジ時間 | 14,283 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 40 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:17:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 17 | scanf("%d%d%d%d%d",&n,&a,&b,&x,&y); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~ main.cpp:19:18: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 19 | rep(i,n)scanf("%d",&h[i]); | ~~~~~^~~~~~~~~~~~
ソースコード
#include<iostream> #include<vector> #include<queue> #include<cassert> #define rep(i,n) for(i=0;i<(int)(n);i++) #define MAX_H (int)(1e9) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int,int> P; int n,a,b,x,y; int main(){ int i,j,left,right,mid; scanf("%d%d%d%d%d",&n,&a,&b,&x,&y); vector<int> h(n); rep(i,n)scanf("%d",&h[i]); auto judge=[&](int k,vector<int> h)->bool{ int i,aa=a; rep(i,n)h[i]-=k; priority_queue<P> PQ; P now; //Magic A rep(i,n)PQ.push(P(h[i],i)); while(PQ.size()&&aa>0){ now=PQ.top();PQ.pop(); if(now.first<=0)break; now.first-=x; h[now.second]-=x; if(now.first>0)PQ.push(now); aa--; } //Magic B ll p=(ll)y*b,d; rep(i,n){ if(h[i]>0){ h[i]-=(d=min(p,(ll)h[i])); p-=d; if(h[i]>0)return false; } } return true; }; left=0;right=MAX_H+1; while(left<right){ mid=(left+right)/2; if(judge(mid,h))right=mid; else left=mid+1; } printf("%d\n",left); return 0; }