QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#497230 | #9133. Function with Many Maximums | ucup-team1134 | AC ✓ | 38ms | 11080kb | C++23 | 1.9kb | 2024-07-28 21:34:32 | 2024-07-28 21:34:32 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=998244353,MAX=300005,INF=15<<26;
int main(){
std::ifstream in("text.txt");
std::cin.rdbuf(in.rdbuf());
cin.tie(0);
ios::sync_with_stdio(false);
ll X=320000000000LL;
vector<ll> A(1000002);
for(ll a=1;a<=200000;a++) A[a]=X-a*1000;
A[200001]=A[200000]-1;
ll cn=0;
ll sz;
for(ll i=200001;cn<=100000;cn++){
if((A[i]*i)%(i+2)==0){
A[i+1]=(A[i]*i)/(i+2);
i++;
}else{
ll L=0,R=(A[i]*i)/(i+3)+1;
while(R-L>1){
ll M=(L+R)/2;
ll a=M,b=(A[i]*i)-a*(i+3);
if(a>=b) R=M;
else L=M;
}
ll a=L,b=(A[i]*i)-a*(i+3);
//ll a=(A[i]*i)/(i+3),b=(A[i]*i)-a*(i+3);
while(1){
//cout<<b<<" "<<a<<endl;
if(A[i]>b&&b>a&&(A[i]*i)>(b)*(i+2)) break;
a--;
b+=(i+3);
}
A[i+1]=b;
A[i+2]=a;
i+=2;
}
//if(cn%100==0) cout<<cn<<endl;
sz=i;
}
cout<<sz<<"\n";
for(ll i=1;i<=sz;i++) cout<<A[i]<<" ";
cout<<endl;
return 0;
vector<ll> S=A;
for(ll i=2;i<=sz;i++){
S[i]+=S[i-1];
}
ll ma=0;
cn=0;
for(ll i=1;i<=sz;i++){
S[i]+=A[i]*i;
if(chmax(ma,S[i])){
cn=1;
}else if(ma==S[i]){
cn++;
}
}
cout<<sz<<endl;
cout<<ma<<" "<<cn<<endl;
}
这程序好像有点Bug,我给组数据试试?
詳細信息
Test #1:
score: 100
Accepted
time: 38ms
memory: 10956kb
input:
4
output:
400002 319999999000 319999998000 319999997000 319999996000 319999995000 319999994000 319999993000 319999992000 319999991000 319999990000 319999989000 319999988000 319999987000 319999986000 319999985000 319999984000 319999983000 319999982000 319999981000 319999980000 319999979000 319999978000 3199999...
result:
ok n=400002, max_a=319999999000, max_num=100002 >= 4
Test #2:
score: 0
Accepted
time: 34ms
memory: 11080kb
input:
100000
output:
400002 319999999000 319999998000 319999997000 319999996000 319999995000 319999994000 319999993000 319999992000 319999991000 319999990000 319999989000 319999988000 319999987000 319999986000 319999985000 319999984000 319999983000 319999982000 319999981000 319999980000 319999979000 319999978000 3199999...
result:
ok n=400002, max_a=319999999000, max_num=100002 >= 100000
Extra Test:
score: 0
Extra Test Passed