一开始就有人带歪榜,差评。
题目链接:https://codeforces.com/gym/102392
B:
solver:lzh
1 #include <bits/stdc++.h> 2 using namespace std; 3 #define ff first 4 #define ss second 5 typedef long long ll; 6 typedef pair<int, int> pii; 7 8 struct node { 9 int t1, t2, e1, e2; 10 } q[510]; 11 ll dp[510][510], tmp[510][510]; 12 int main() { 13 int n, s1, s2; 14 scanf("%d%d%d", &n, &s1, &s2); 15 for (int i = 1; i <= n; i++) 16 scanf("%d%d%d%d", &q[i].e1, &q[i].t1, &q[i].e2, &q[i].t2); 17 sort(q + 1, q + 1 + n, [](node a, node b) { 18 return a.e1 < b.e1; 19 }); 20 for (int i = 0; i <= s1; i++) 21 for (int j = 0; j <= s2; j++) 22 dp[i][j] = 1e18; 23 dp[0][0] = 0; 24 for (int i = 1; i <= n; i++) { 25 for (int j = 0; j <= s1; j++) 26 for (int k = 0; k <= s2; k++) 27 tmp[j][k] = dp[j][k]; 28 29 for (int j = s1; j >= 0; j--) 30 for (int k = s2; k >= 0; k--) 31 if (dp[j][k] != 1e18) { 32 if (j < s1) { 33 int minj = j + q[i].e1, mink = k; 34 if (minj > s1) { 35 mink = min(s2, minj - s1 + k); 36 minj = s1; 37 } 38 tmp[minj][mink] = min(tmp[minj][mink], dp[j][k] + q[i].t1); 39 } 40 int mink = min(s2, k + q[i].e2); 41 tmp[j][mink] = min(tmp[j][mink], dp[j][k] + q[i].t2); 42 } 43 44 for (int j = 0; j <= s1; j++) 45 for (int k = 0; k <= s2; k++) 46 dp[j][k] = tmp[j][k]; 47 } 48 if (dp[s1][s2] == 1e18 || dp[s1][s2] == 0) 49 dp[s1][s2] = -1; 50 printf("%lld ", dp[s1][s2]); 51 }
D:
solver:zyh、czq
1 /* basic header */ 2 #include <bits/stdc++.h> 3 /* define */ 4 #define ll long long 5 #define pb emplace_back 6 #define mp make_pair 7 #define eps 1e-8 8 #define lson (curpos<<1) 9 #define rson (curpos<<1|1) 10 /* namespace */ 11 using namespace std; 12 /* header end */ 13 14 const int maxn = 1e6 + 10; 15 char s[maxn]; 16 int n, cnt[26], over = -1, kinds = 0; 17 18 int main() { 19 scanf("%s", s + 1); 20 n = strlen(s + 1) / 2; 21 for (int i = 1; i <= 2 * n; i++) { 22 if (!cnt[s[i] - 'a']) kinds++; 23 cnt[s[i] - 'a']++; 24 if (cnt[s[i] - 'a'] > n) over = s[i] - 'a'; 25 } 26 27 if (over == -1) { 28 puts("YES"); 29 for (int i = 0; i < 26; i++) { 30 while (cnt[i]--) printf("%c", char(i + 'a')); 31 } 32 return 0; 33 } 34 35 if (cnt[over] >= 2 * n - 1) return puts("NO"), 0; 36 if (cnt[over] >= 2 * n - 2 && kinds == 2) return puts("NO"), 0; 37 puts("YES"); 38 for (int i = 1; i <= n; i++) printf("%c", over + 'a'), cnt[over]--; 39 for (int i = 0, j = 0; i < 26, j < kinds / 2; i++) { 40 if (i != over && cnt[i]) { 41 j++; 42 cnt[i]--; 43 printf("%c", i + 'a'); 44 } 45 } 46 while (cnt[over]--) printf("%c", over + 'a'); 47 for (int i = 0; i < 26; i++) { 48 if (i != over) { 49 while (cnt[i]--) printf("%c", i + 'a'); 50 } 51 } 52 puts(""); 53 return 0; 54 }
E:
solver:zyh、lzh、czq
1 #include <bits/stdc++.h> 2 using namespace std; 3 int a[200001]; 4 long long mneed[200001]; 5 long long msum[200001]; 6 long long cneed[200001]; 7 long long csum[200001]; 8 long long query(long long presum[],int l,int r){ 9 return presum[l]-presum[r+1]; 10 } 11 int main(){ 12 int n,k; 13 int lc,lm; 14 long long pc,pm; 15 int t,d; 16 scanf("%d%d",&n,&k); 17 scanf("%d%lld%d%lld",&lc,&pc,&lm,&pm); 18 scanf("%d%d",&t,&d); 19 for (int i=0;i<n;++i) scanf("%d",&a[i]); 20 sort(a,a+n); 21 mneed[n]=msum[n]=cneed[n]=csum[n]=0; 22 for (int i=n-1;i>=0;--i){ 23 mneed[i]=mneed[i+1]+max(lm-a[i],0); 24 cneed[i]=cneed[i+1]+max(lc-a[i],0); 25 msum[i]=msum[i+1]+max(a[i]-lm,0); 26 csum[i]=csum[i+1]+max(a[i]-lc,0); 27 } 28 29 long long sum=0; 30 long long ans=__LONG_LONG_MAX__; 31 for (int c=0;c*k<n;++c){ 32 int m=n-c*k; 33 for (int j=max(0,(c-1)*(k-1));j<c*(k-1);++j){ 34 sum+=min(d,a[j]-1); 35 } 36 if (lc<lm){ 37 if (sum+query(csum,n-m-c,n-m-1)+query(msum,n-m,n-1)>=query(cneed,n-m-c,n-m-1)+query(mneed,n-m,n-1)){ 38 //cout<<query(cneed,n-m-c,n-m-1)+query(mneed,n-m,n-1)<<endl; 39 //cout<<c<<' '<<m<<endl; 40 long long price=(query(cneed,n-m-c,n-m-1)+query(mneed,n-m,n-1))*t+pc*c+pm*m; 41 ans=min(ans,price); 42 } 43 }else { 44 if (sum+query(msum,n-m-c,n-c-1)+query(csum,n-c,n-1)>=query(mneed,n-m-c,n-c-1)+query(cneed,n-c,n-1)){ 45 //cout<<c<<' '<<m<<endl; 46 long long price=(query(mneed,n-m-c,n-c-1)+query(cneed,n-c,n-1))*t+pc*c+pm*m; 47 ans=min(ans,price); 48 } 49 } 50 } 51 //special case: all in car 52 int c=(n+k-1)/k; 53 sum=0; 54 for (int i=0;i<n-c;++i) sum+=min(d,a[i]-1); 55 if (sum+query(csum,n-c,n-1)>=query(cneed,n-c,n-1)){ 56 long long price=query(cneed,n-c,n-1)*t+pc*c; 57 //cout<<c<<endl; 58 ans=min(ans,price); 59 } 60 61 if (ans==__LONG_LONG_MAX__) printf("-1 "); 62 else printf("%lld ",ans); 63 }
F:
solver:czq
1 /* basic header */ 2 #include <bits/stdc++.h> 3 /* define */ 4 #define ll long long 5 #define pb emplace_back 6 #define mp make_pair 7 #define eps 1e-8 8 #define lson (curpos<<1) 9 #define rson (curpos<<1|1) 10 /* namespace */ 11 using namespace std; 12 /* header end */ 13 14 const int maxn = 1e5 + 10; 15 vector<int>tree[maxn]; 16 int n; 17 18 int dfs(int u, int fa) { 19 int ret = 0; 20 for (auto v : tree[u]) { 21 if (v == fa) continue; 22 ret += dfs(v, u); 23 } 24 ret += ret ? -1 : 1; 25 return ret; 26 } 27 28 int main() { 29 scanf("%d", &n); 30 for (int i = 1; i < n; i++) { 31 int u, v; scanf("%d%d", &u, &v); 32 tree[u].pb(v), tree[v].pb(u); 33 } 34 printf("%s ", dfs(1, -1) ? "Alice" : "Bob"); 35 return 0; 36 }
G:
solver:zyh
1 #include <bits/stdc++.h> 2 using namespace std; 3 struct projection { 4 int x, y; 5 projection() {} 6 projection(int _x, int _y) { 7 x = _x; 8 y = _y; 9 } 10 }; 11 vector<int> y[201]; 12 vector<int> z[201]; 13 bool check(int n) { 14 for (int i = 0; i < n; ++i) { 15 if (y[i].size() > 0 && z[i].size() == 0) return false; 16 if (y[i].size() == 0 && z[i].size() > 0) return false; 17 } 18 return true; 19 } 20 int main() { 21 int n, m, h; 22 scanf("%d%d%d", &n, &m, &h); 23 for (int i = 0; i < n; ++i) 24 for (int j = 0; j < m; ++j) { 25 char ch; 26 scanf(" %c", &ch); 27 if (ch == '1') y[i].push_back(j); 28 } 29 for (int i = 0; i < n; ++i) 30 for (int j = 0; j < h; ++j) { 31 char ch; 32 scanf(" %c", &ch); 33 if (ch == '1') z[i].push_back(j); 34 } 35 if (!check(n)) { 36 printf("-1"); 37 return 0; 38 } 39 int ans = 0; 40 for (int x = 0; x < n; ++x) ans += y[x].size() * z[x].size(); 41 printf("%d ", ans); 42 for (int x = 0; x < n; ++x) { 43 for (auto Y : y[x]) 44 for (auto Z : z[x]) { 45 printf("%d %d %d ", x, Y, Z); 46 } 47 } 48 ans = 0; 49 for (int x = 0; x < n; ++x) ans += max(y[x].size(), z[x].size()); 50 printf("%d ", ans); 51 for (int x = 0; x < n; ++x) { 52 int leny = y[x].size(); 53 int lenz = z[x].size(); 54 int len = max(leny, lenz); 55 for (int i = len; i >= 1; --i) { 56 printf("%d %d %d ", x, y[x][max(0, leny - i)], z[x][max(0, lenz - i)]); 57 } 58 } 59 }
I:
solver:czq
1 /* basic header */ 2 #include <bits/stdc++.h> 3 /* define */ 4 #define ll long long 5 #define pb emplace_back 6 #define mp make_pair 7 #define eps 1e-8 8 #define lson (curpos<<1) 9 #define rson (curpos<<1|1) 10 /* namespace */ 11 using namespace std; 12 /* header end */ 13 14 int n, ans = 0; 15 16 int main() { 17 ios::sync_with_stdio(false); 18 cin.tie(0); 19 20 cin >> n; 21 vector<int>a(n), b(n); 22 for (auto &i : a) cin >> i; 23 for (auto &i : b) cin >> i; 24 for (auto i : a) { 25 int curr = INT_MAX; 26 for (auto j : b) curr = min(curr, abs(i - j)); 27 ans = max(ans, curr); 28 } 29 cout << ans << endl; 30 return 0; 31 }
J:
solver:zyh、czq
1 #include <bits/stdc++.h> 2 using namespace std; 3 4 const int maxn = 1e3 + 10; 5 vector<int>e[maxn]; 6 7 int main() { 8 int n; 9 scanf("%d", &n); 10 for (int i = 0; i < n * (n - 1) / 2; ++i) { 11 int u, v, w; 12 scanf("%d%d%d", &u, &v, &w); 13 e[u].push_back(w); 14 e[v].push_back(w); 15 } 16 long long ans = 0; 17 for (int i = 1; i <= n; ++i) { 18 sort(e[i].begin(), e[i].end()); 19 for (int j = 0; j < e[i].size(); j += 2) ans += max(e[i][j], e[i][j + 1]); 20 } 21 tuple<int, int, int>t; 22 t. 23 printf("%lld ", ans); 24 }