提出 #34483869
ソースコード 拡げる
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a,n) for (ll i=a;i<(ll)n;i++)
ll read(){ll r;scanf("%lld",&r);return r;} // read
char s[200010];
ll k;
vector<int> v;
vector<ll> pre = {0};
tuple<ll,ll,ll> calc(ll x,ll d){ // value = x, distance = d , return {<d的和, <d 的个数, =m的个数}
// [x-d,x+d]
int i = lower_bound(v.begin(),v.end(),x ) - v.begin();
int i0 = lower_bound(v.begin(),v.end(),x-d ) - v.begin();
int i1 = lower_bound(v.begin(),v.end(),x-d+1) - v.begin();
int i2 = lower_bound(v.begin(),v.end(),x+d ) - v.begin();
int i3 = lower_bound(v.begin(),v.end(),x+d+1) - v.begin();
if(d == 0) return {0,0,i1-i0};
// [i0 [i1 i i2] i3]
// [i1..i-1] + [i..i2-1]
ll sum = (i-i1) * x - (pre[i] - pre[i1])
+ (pre[i2] - pre[i]) - (i2-i) * x;
return {sum, i2-i1, (i1-i0)+(i3-i2) };
}
ll f(ll x){
ll l = 0;
ll r = max(x-v[0],v.back()-x)+1;
while(l+1 < r){
ll mid = (l+r)/2;
(get<0>(calc(x, mid)) > k ? r : l) = mid;
}
auto [sum, c0, c1] = calc(x, l);
return c0 + (l==0 ? c1 : min((k-sum)/l,c1));
}
int main(){
scanf("%s",s);
int n = strlen(s);
k = read();
rep(i,0,n) if(s[i] == 'Y'){ v.push_back(i-v.size()); }
rep(i,0,v.size()) pre.push_back(pre.back() + v[i]);
ll ans = 0;
for(auto x:v) ans = max(ans, f(x));
printf("%lld\n",ans);
return 0;
}
提出情報
| 提出日時 | |
|---|---|
| 問題 | G - Longest Y |
| ユーザ | cromarmot |
| 言語 | C++ (GCC 9.2.1) |
| 得点 | 600 |
| コード長 | 1364 Byte |
| 結果 | AC |
| 実行時間 | 333 ms |
| メモリ | 6300 KiB |
コンパイルエラー
./Main.cpp: In function ‘ll read()’:
./Main.cpp:7:21: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
7 | ll read(){ll r;scanf("%lld",&r);return r;} // read
| ~~~~~^~~~~~~~~~~
./Main.cpp: In function ‘int main()’:
./Main.cpp:42:8: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
42 | scanf("%s",s);
| ~~~~~^~~~~~~~
ジャッジ結果
| セット名 | Sample | All | ||||
|---|---|---|---|---|---|---|
| 得点 / 配点 | 0 / 0 | 600 / 600 | ||||
| 結果 |
|
|
| セット名 | テストケース |
|---|---|
| Sample | example0.txt, example1.txt |
| All | 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, 024.txt, 025.txt, 026.txt, 027.txt, 028.txt, 029.txt, 030.txt, 031.txt, 032.txt, 033.txt, 034.txt, 035.txt, 036.txt, 037.txt, 038.txt, 039.txt, 040.txt, 041.txt, 042.txt, 043.txt, 044.txt, 045.txt, 046.txt, 047.txt, 048.txt, 049.txt, 050.txt, 051.txt, 052.txt, 053.txt, 054.txt, 055.txt, 056.txt, 057.txt, example0.txt, example1.txt |
| ケース名 | 結果 | 実行時間 | メモリ |
|---|---|---|---|
| 000.txt | AC | 7 ms | 3568 KiB |
| 001.txt | AC | 2 ms | 3744 KiB |
| 002.txt | AC | 2 ms | 3664 KiB |
| 003.txt | AC | 6 ms | 3860 KiB |
| 004.txt | AC | 4 ms | 3760 KiB |
| 005.txt | AC | 29 ms | 6220 KiB |
| 006.txt | AC | 2 ms | 3624 KiB |
| 007.txt | AC | 2 ms | 3744 KiB |
| 008.txt | AC | 296 ms | 4728 KiB |
| 009.txt | AC | 203 ms | 4652 KiB |
| 010.txt | AC | 3 ms | 3840 KiB |
| 011.txt | AC | 4 ms | 3792 KiB |
| 012.txt | AC | 3 ms | 3916 KiB |
| 013.txt | AC | 3 ms | 3856 KiB |
| 014.txt | AC | 6 ms | 3800 KiB |
| 015.txt | AC | 30 ms | 3816 KiB |
| 016.txt | AC | 53 ms | 3912 KiB |
| 017.txt | AC | 67 ms | 3992 KiB |
| 018.txt | AC | 53 ms | 3992 KiB |
| 019.txt | AC | 5 ms | 3756 KiB |
| 020.txt | AC | 48 ms | 3872 KiB |
| 021.txt | AC | 93 ms | 4060 KiB |
| 022.txt | AC | 119 ms | 4580 KiB |
| 023.txt | AC | 100 ms | 4620 KiB |
| 024.txt | AC | 2 ms | 3720 KiB |
| 025.txt | AC | 4 ms | 3684 KiB |
| 026.txt | AC | 5 ms | 3640 KiB |
| 027.txt | AC | 6 ms | 3716 KiB |
| 028.txt | AC | 6 ms | 3820 KiB |
| 029.txt | AC | 12 ms | 4008 KiB |
| 030.txt | AC | 128 ms | 4188 KiB |
| 031.txt | AC | 234 ms | 4812 KiB |
| 032.txt | AC | 305 ms | 6032 KiB |
| 033.txt | AC | 252 ms | 6172 KiB |
| 034.txt | AC | 11 ms | 3800 KiB |
| 035.txt | AC | 115 ms | 4220 KiB |
| 036.txt | AC | 227 ms | 4876 KiB |
| 037.txt | AC | 277 ms | 6072 KiB |
| 038.txt | AC | 248 ms | 6220 KiB |
| 039.txt | AC | 11 ms | 3880 KiB |
| 040.txt | AC | 134 ms | 4280 KiB |
| 041.txt | AC | 267 ms | 4876 KiB |
| 042.txt | AC | 333 ms | 5908 KiB |
| 043.txt | AC | 251 ms | 6300 KiB |
| 044.txt | AC | 4 ms | 3816 KiB |
| 045.txt | AC | 3 ms | 3892 KiB |
| 046.txt | AC | 8 ms | 3876 KiB |
| 047.txt | AC | 7 ms | 3788 KiB |
| 048.txt | AC | 17 ms | 3936 KiB |
| 049.txt | AC | 15 ms | 3936 KiB |
| 050.txt | AC | 35 ms | 4104 KiB |
| 051.txt | AC | 29 ms | 4052 KiB |
| 052.txt | AC | 111 ms | 4192 KiB |
| 053.txt | AC | 112 ms | 4108 KiB |
| 054.txt | AC | 212 ms | 4560 KiB |
| 055.txt | AC | 209 ms | 4800 KiB |
| 056.txt | AC | 160 ms | 4748 KiB |
| 057.txt | AC | 159 ms | 4880 KiB |
| example0.txt | AC | 2 ms | 3668 KiB |
| example1.txt | AC | 2 ms | 3616 KiB |