版本比较
模拟赛代码
正文
增加 59 行删除 53 行
123356789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616256636458```cpp#include<bits/stdc++.h>#define int long longusing namespace std;constexpr int Maxn=3e6+5;int l,L,n,a[Maxn],Last,Next[Maxn],x,ans;string s;signed main(){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); freopen("toy.in","r",stdin); freopen("toy.out","w",stdout); cin>>l>>L>>n; cin>>s; s='c'+s; if(L==n){ for(int i=1; i<=n; i++){ if(s[i]=='1')x++; } if(x==l)cout<<0; else cout<<l; return 0; } Last=1; for(int i=2; i<=n; i++){ if(s[i]=='1'){ Next[Last]=i; Last=i; } } a[l]=1; for(int i=l+1; i<=n; i++){ a[i]=a[i-1]; if(s[i]=='1'){ a[i]=Next[a[i]]; } } x=L; while(true){ ans+=l; if(x==n)break; Last=a[x]; x=min(a[x]+L-1,n); if(Last==a[x]&&x!=n){ cout<<"IMPOSSIBLE"; exit(0); } } cout<<ans+n-L; return 0;}/*longlongconst int N = 3010;const int inf = 0x3f3f3f3f;int n, m, f[N];struct Node{ int l, r;}no[N];bool vis[N];//初始状态int main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); freopen("spring.in", "r", stdin); freopen("spring.out", "w", stdout); cin >> n >> m; for(int i = 1; i <= n; ++i){ cin >> no[i].l >> no[i].r; for(int j = no[i].l; j <= no[i].r; ++j){ vis[j] = true; } } memset(f, inf, sizeof(f)); n += 2; no[n - 1] = {0, 0}; no[n] = {m + 1, m + 1}; f[0] = 0; for(int i = 1; i <= m; ++i){//哪个点 if(vis[i]){ f[i] = f[i - 1]; continue; } for(int j = 1; j <= n; ++j){//使用哪个弹簧 if(no[j].r < i){//从左边扩展 int more = i - no[j].r; if(no[j].l - more - 1 < 1) f[i] = min(f[i], more); else f[i] = min(f[i], f[no[j].l - more - 1] + more); // cout << i << " " << j << " " << f[i] << " " << more << endl; } } } cout << f[m] << endl; return 0;}/*T1 spring 超级弹簧考虑f[i]表示覆盖i最少使用的次数到一个点时枚举所有弹簧覆盖n<=3000...按左端点排序后贪心 不对 一定用最近的吗 - 事实上不一定中英一定要互译-----------2026年NOICA联盟-NOIP模拟赛(十七)-DIV2----------8:05 不是下发文件炸了只能用Div1的了8:29 T2搞定了,但没有大样例,再说8:41 T3有点思路但不确定正确性,先开T48:45 不是现在大样例上去了...等一会测一下T2吧9:10 T1思路很巧妙,这是怎么想到的9:28 T2没取模气笑了9:29 T2没毛病li(喜)9:59 T3 OK了,兵贵神速啊 验证一下复杂度 时间没问题11:04 T4答案稍小,祭11:21 T4极限数据跑了10s,气死我了,不过至少得到72pts了,好耶11:43 T4优化到6.3s了,就差一点(bushi) 5.7s了
?预计分数: 100 + 100 + 100 + 72 = 372*/```