結果
| 問題 |
No.1211 円環はお断り
|
| コンテスト | |
| ユーザー |
vjudge1
|
| 提出日時 | 2024-09-07 22:40:03 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,521 bytes |
| コンパイル時間 | 2,102 ms |
| コンパイル使用メモリ | 193,556 KB |
| 最終ジャッジ日時 | 2025-02-24 05:12:14 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 32 WA * 2 TLE * 7 |
ソースコード
#include<bits/stdc++.h>
#define int long long
using namespace std;
#define fi first
#define sc second
#define pii pair<int,int>
#define pb push_back
const int maxn=6e5+10;
int n,k,a[maxn],s[maxn],nxt[maxn][20],f[maxn];
namespace Fast_IO
{
static char buf[1000000],*paa=buf,*pd=buf,out[10000000];int length=0;
#define getchar() paa==pd&&(pd=(paa=buf)+fread(buf,1,1000000,stdin),paa==pd)?EOF:*paa++
inline int read()
{
int x(0),t(1);char fc(getchar());
while(!isdigit(fc)){if(fc=='-') t=-1;fc=getchar();}
while(isdigit(fc)) x=(x<<1)+(x<<3)+(fc^48),fc=getchar();
return x*t;
}
inline void flush(){fwrite(out,1,length,stdout);length=0;}
inline void put(char c){if(length==9999999) flush();out[length++]=c;}
inline void put(string s){for(char c:s) put(c);}
inline void print(int x)
{
if(x<0) put('-'),x=-x;
if(x>9) print(x/10);
put(x%10+'0');
}
inline bool chk(char c) { return !(c>='a'&&c<='z'||c>='A'&&c<='Z'||c>='0'&&c<='9'); }
inline bool ck(char c) { return c!='\n'&&c!='\r'&&c!=-1&&c!=' '; }
inline void rd(char s[],int&n)
{
s[++n]=getchar();
while(chk(s[n])) s[n]=getchar();
while(ck(s[n])) s[++n]=getchar();
n--;
}
}
using namespace Fast_IO;
bool chk(int x)
{
for(int i=1;i<=n*2;i++) { nxt[i][0]=lower_bound(s+1,s+n*2+1,s[i]+x)-s; }
for(int i=0;i<=19;i++) nxt[n*2+1][i]=n*2+1;
for(int i=1;i<=19;i++) { for(int j=1;j<=n*2;j++) nxt[j][i]=nxt[nxt[j][i-1]][i-1]; }
for(int i=1;i<=n;i++)
{
nxt[n*2][0]=n*2;
int now=i;
for(int j=0;j<=19;j++) { if(k&(1<<j)) now=nxt[now][j]; }
if(now-i<=n) return 1;
}
return 0;
}
void solve()
{
cin>>n>>k;
for(int i=1;i<=n;i++) cin>>a[i],a[i+n]=a[i];
for(int i=1;i<=n*2;i++) s[i]=s[i-1]+a[i];
int l=0,r=1e10,mid=0;
while(l<=r) mid=(l+r)>>1,(chk(mid)?l=mid+1:r=mid-1);
l--,cout<<l<<" ";
for(int i=1;i<=n*2;i++) { nxt[i][0]=lower_bound(s+1,s+n*2+1,s[i]+l)-s; }
for(int i=0;i<=19;i++) nxt[n*2+1][i]=n*2+1;
for(int i=1;i<=19;i++) { for(int j=1;j<=n*2;j++) nxt[j][i]=nxt[nxt[j][i-1]][i-1]; }
int res=0;
for(int i=1;i<=n;i++)
{
nxt[n*2][0]=n*2;
int now=i;
for(int j=0;j<=19;j++) { if(k&(1<<j)) now=nxt[now][j]; }
res+=(now-i>n);
}
// cout<<res<<endl;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
int t=1;
// cin>>t;
while(t--) solve();
return 0;
}
vjudge1