A |
- #include<vector>
- #include<iostream>
- using namespace std;
- int main(){
- int n;
- cin>>n;
- vector<int>a(n);
- vector<int>b(n,0);
- int sum=0;
- int sum1=0;
- int cnt=1;
- for(int i=0;i<n;i++)
- {
- cin >> a[i];
- sum+=a[i];
- if(a[i]<a[0]/2+1)
- {
- b[i]=1;
- cnt++;
- sum1+=a[i];
- }
- }
- b[0]=1;
- sum1+=a[0];
- if(2*sum1<=sum)
- cout<<"0"<<endl;
- else
- {
- cout<<cnt<<endl;
- for(int i=0;i<n;i++)
- {
- if(b[i]==1)
- cout<<i+1<<" ";
- }
- }
- return 0;
- }
B |
- #include <iostream>
- #include <string>
- #include <vector>
- using namespace std;
- using LL = long long;
- int main()
- {
- LL result = 0;
- string s;
- cin >> s;
- vector<LL> prefix_vn(s.length());
- vector<LL> suffix_vn(s.length());
- for (LL i = 0; i < s.length() - 1; ++i)
- {
- if (s[i] == 'v' && i > 0 && s[i - 1] == 'v')
- prefix_vn[i + 1] = 1;
- prefix_vn[i + 1] += prefix_vn[i];
- }
- for (LL i = 0; i < s.length() - 1; ++i)
- {
- if (s[s.length() - i - 1] == 'v' && i > 0 && s[s.length() - i] == 'v')
- suffix_vn[s.length() - i - 2] = 1;
- suffix_vn[s.length() - i - 2] += suffix_vn[s.length() - i - 1];
- }
- for (LL i = 0; i < s.length(); ++i)
- if (s[i] == 'o')
- result += prefix_vn[i] * suffix_vn[i];
- cout << result << '\n';
- return 0;
- }
C |
- #include <iostream>
- using namespace std;
- using LL = long long;
- const LL MODULO = 998'244'353;
- LL fast_pow(LL base, LL exp)
- {
- LL result = 0, mult = 0;
- result = 1;
- mult = base;
- while (exp > 0)
- {
- if (exp % 2 == 1)
- result = result * mult % MODULO;
- mult = mult * mult % MODULO;
- exp /= 2;
- }
- return result;
- }
- int main()
- {
- LL width = 0, height = 0;
- cin >> width >> height;
- cout << fast_pow(2, width + height) << '\n';
- return 0;
- }
D |
- #include <iostream>
- #include <vector>
- using namespace std;
- bool is_prime(int n)
- {
- if (n <= 1)
- return false;
- for (int f = 2; f * f <= n; ++f)
- if (n % f == 0)
- return false;
- return true;
- }
- const int N = 1'000;
- int degrees[N];
- int main()
- {
- int n = 0, extra = 0;
- cin >> n;
- vector<pair<int, int>> edges;
- for (int i = 0; i < n; ++i)
- edges.push_back({i, (i + 1) % n});
- while (!is_prime(n + extra))
- ++extra;
- for (int i = 0; i < extra; ++i)
- edges.push_back({i, (i + n / 2) % n});
- cout << n + extra << '\n';
- for (int i = 0; i < n + extra; ++i)
- cout << edges[i].first + 1 << ' ' << edges[i].second + 1 << '\n';
- return 0;
- }
E |
- #include <bits/stdc++.h>
- using namespace std;
- string s;
- char cur;
- int l,r;
- void solve()
- {
- cin>>s;
- deque<int>a,b,c;
- for(int i=0;i<s.size();i++)
- {
- if(s[i]=='a')a.push_back(i);
- else if(s[i]=='b')b.push_back(i);
- else c.push_back(i);
- if(s.size()%2==1&&i==s.size()/2)cur=s[i];
- }
- string ans="";
- if(a.size()>=s.size()/2)
- {
- for(int i=1;i<=s.size()/2;i++)cout<<'a';
- puts("");
- return;
- }
- if(b.size()>=s.size()/2)
- {
- for(int i=1;i<=s.size()/2;i++)cout<<'b';
- puts("");
- return;
- }
- if(c.size()>=s.size()/2)
- {
- for(int i=1;i<=s.size()/2;i++)cout<<'c';
- puts("");
- return;
- }
- int maxx;
- while(1)
- {
- maxx=max(max(a.back()-a.front(),b.back()-b.front()),c.back()-c.front());
- if(maxx==a.back()-a.front())
- {
- l=a.front(),r=a.back();
- ans+='a';
- }
- else if(maxx==b.back()-b.front())
- {
- l=b.front(),r=b.back();
- ans+='b';
- }
- else
- {
- l=c.front(),r=c.back();
- ans+='c';
- }
- while(!a.empty()&&a.front()<=l)a.pop_front();
- while(!b.empty()&&b.front()<=l)b.pop_front();
- while(!c.empty()&&c.front()<=l)c.pop_front();
- while(!a.empty()&&a.back()>=r)a.pop_back();
- while(!b.empty()&&b.back()>=r)b.pop_back();
- while(!c.empty()&&c.back()>=r)c.pop_back();
- if(a.size()<=1&&b.size()<=1&&c.size()<=1)break;
- }
- //reverse(ans.begin(),ans.end());
- if(ans.size()*2+(a.size()>=1||b.size()>=1||c.size()>=1)<s.size()/2)
- {
- puts("IMPOSSIBLE");
- return;
- }
- cout<<ans;
- if(a.size()>=1)cout<<'a';
- else if(b.size()>=1)cout<<'b';
- else if(c.size()>=1)cout<<'c';
- reverse(ans.begin(),ans.end());
- cout<<ans;
- puts("");
- }
- int main()
- {
- int t=1;
- //cin>>t;
- while(t--)solve();
- }