2 条题解
-
0
#include<bits/stdc++.h> char s[200001]; int t; struct node { int a,b; }v[200001]; bool cmp(node x,node y) { return (long long)x.b*y.a<(long long)y.b*x.a; } int main() { scanf("%d",&t); long long ans=0; for(int i=1;i<=t;i+=1) { scanf("%s",s); int n=strlen(s); int cnt=0; for(int i=0;i<n;i+=1) { if(s[i]=='1')cnt+=1; else ans+=cnt; } v[i]={n-cnt,cnt}; } std::sort(v+1,v+t+1,cmp); long long sum=0; for(int i=1;i<=t;i+=1) { ans+=v[i].a*sum; sum+=v[i].b; } std::cout<<ans<<std::endl; }
-
0
#include <bits/stdc++.h> using namespace std; #define ll long long char s[200005]; int t; struct node{ int a, b; } v[200005]; bool cmp(node x, node y){ return (ll)x.b * y.a < (ll)y.b * x.a; } int main(){ scanf("%d", &t); ll ans = 0; for (int i = 1; i <= t; ++i){ scanf("%s", s); int n = strlen(s); int cnt = 0; for (int i = 0; i < n; ++i){ if (s[i] == '1') ++cnt; else ans += cnt; } v[i] = {n - cnt, cnt}; } sort(v + 1, v + 1 + t, cmp); ll sum = 0; for (int i = 1; i <= t; ++i){ ans += v[i].a * sum; sum += v[i].b; } cout << ans << endl; return 0; }
- 1
信息
- ID
- 570
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 6
- 标签
- (无)
- 递交数
- 696
- 已通过
- 213
- 上传者