QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#455140 | #6462. Jewel Thief | do_while_true | WA | 1ms | 7640kb | C++17 | 3.1kb | 2024-06-25 20:31:16 | 2024-06-25 20:31:16 |
Judging History
answer
#include<cstdio>
#include<vector>
#include<queue>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<ctime>
#include<bitset>
#include<random>
#include<array>
#include<assert.h>
#include<functional>
#define pb emplace_back
#define mp make_pair
#define fi first
#define se second
#define dbg(x) cerr<<"In Line "<< __LINE__<<" the "<<#x<<" = "<<x<<'\n'
#define dpi(x,y) cerr<<"In Line "<<__LINE__<<" the "<<#x<<" = "<<x<<" ; "<<"the "<<#y<<" = "<<y<<'\n'
#define DE(fmt,...) fprintf(stderr, "Line %d : " fmt "\n",__LINE__,##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef __int128 i128;
typedef pair<int,int>pii;
typedef pair<ll,int>pli;
typedef pair<ll,ll>pll;
typedef pair<int,ll>pil;
typedef vector<int>vi;
typedef vector<ll>vll;
typedef vector<pii>vpii;
typedef vector<pll>vpll;
template<typename T>T cmax(T &x, T y){return x=x>y?x:y;}
template<typename T>T cmin(T &x, T y){return x=x<y?x:y;}
template<typename T>
T &read(T &r){
r=0;bool w=0;char ch=getchar();
while(ch<'0'||ch>'9')w=ch=='-'?1:0,ch=getchar();
while(ch>='0'&&ch<='9')r=r*10+(ch^48),ch=getchar();
return r=w?-r:r;
}
template<typename T1,typename... T2>
void read(T1 &x,T2& ...y){read(x);read(y...);}
const int mod=998244353;
const int bas=20201205;
inline void cadd(int &x,int y){x=(x+y>=mod)?(x+y-mod):(x+y);}
inline void cdel(int &x,int y){x=(x-y<0)?(x-y+mod):(x-y);}
inline int add(int x,int y){return (x+y>=mod)?(x+y-mod):(x+y);}
inline int del(int x,int y){return (x-y<0)?(x-y+mod):(x-y);}
int qpow(int x,int y){
int s=1;
while(y){
if(y&1)s=1ll*s*x%mod;
x=1ll*x*x%mod;
y>>=1;
}
return s;
}
const int N=300010;
const int M=N*5;
const ll inf=0x3f3f3f3f3f3f3f3f;
int n,m;
int b[N];
ll c[N];
ll f[M],g[M];
vll vec[310];
signed main(){
#ifdef do_while_true
assert(freopen("data.in","r",stdin));
#endif
read(n);
int mx=0;
for(int i=1;i<=n;i++)read(b[i]),m+=b[i],cmax(mx,b[i]);
for(int i=1;i<=n;i++)read(c[i]);
for(int i=1;i<=n;i++)vec[b[i]].pb(c[i]);
for(int o=1;o<=mx;o++)if(!vec[o].empty()){
sort(vec[o].begin(),vec[o].end(),greater<int>());
int len=vec[o].size();
for(int i=1;i<len;i++)vec[o][i]+=vec[o][i-1];
vec[o].insert(vec[o].begin(),0ll);
for(int p=0;p<o;p++){
function<void(int,int,int,int)>solve=[&](int l,int r,int L,int R){
if(l>r)return ;
int mid=(l/o+r/o)/2*o+p;
int pos=0;ll mx=-inf;
for(int i=L;i<=min(mid,R);i+=o){
ll w=f[i]+vec[o][min(len,(mid-i)/o)];
if(w>mx){
mx=w;
pos=i;
}
}
g[mid]=mx;
solve(l,mid-o,L,pos);
solve(mid+o,r,pos,R);
};
int t=m;
while(t%o!=p)--t;
if(p<=t){
// DE("p=%d t=%d",p,t);
solve(p,t,p,t);
}
}
for(int i=1;i<=m;i++)f[i]=max(f[i-1],g[i]),g[i]=0;
}
// for(int i=0;i<=m;i++)cerr<<f[i]<<' ';
// cerr<<'\n';
int ans=0;
for(int i=m;i>=0;i--){
ans=(1ll*ans*bas%mod+f[i]%mod)%mod;
}
ans=1ll*ans*bas%mod;
cout<<ans<<'\n';
#ifdef do_while_true
// cerr<<'\n'<<"Time:"<<1.0*clock()/CLOCKS_PER_SEC*1000<<" ms"<<'\n';
#endif
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 7640kb
input:
4 9 2 8 1 1 3 4 5 100
output:
142643352
result:
wrong answer 1st lines differ - expected: '1 8 9 9 100 101 108 109 109', found: '142643352'