Educational Codeforces Round 77 (Rated for Div. 2)
A. Heating
Several days ago you bought a new house and now you are planning to start a renovation. Since winters in your region can be very cold you need to decide how to heat rooms in your house.
Your house has k2 burles.
Since rooms can have different sizes, you calculated that you need at least i-th room.
For each room calculate the minimum cost to install at most sumi.
The first line contains single integer 1≤n≤1000) — the number of rooms.
Each of the next i-th room, respectively.
For each room print one integer — the minimum possible cost to install at most sumi.
4 1 10000 10000 1 2 6 4 6
100000000 1 18 10
In the first room, you can install only one radiator, so it's optimal to use the radiator with (104)2=108.
In the second room, you can install up to 104 radiators, but since you need only one section in total, it's optimal to buy one radiator with one section.
In the third room, there 32+32=18.
#include <iostream> #include <algorithm> #include <cstdio> #include <string> #include <cstring> #include <cstdlib> #include <map> #include <vector> #include <set> #include <queue> #include <stack> #include <cmath> using namespace std; #define mem(s,t) memset(s,t,sizeof(s)) #define pq priority_queue #define pb push_back #define fi first #define se second #define ac return 0; #define ll long long #define cin2(a,n,m) for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) cin>>a[i][j]; #define rep_(n,m) for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) #define rep(n) for(int i=1;i<=n;i++) #define test(xxx) cout<<" Test " <<" "<<xxx<<endl; #define TLE std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cout.precision(10); #define lc now<<1 #define rc now<<1|1 #define ls now<<1,l,mid #define rs now<<1|1,mid+1,r #define half no[now].l+((no[now].r-no[now].l)>>1) #define ll long long #define mod 1000000007 const int mxn = 1e6+10; ll n,m,k,ans,col,t,flag,x,y,pim[mxn]; ll a[mxn],sum[mxn],cnt,vis[mxn]; vector<int>G[mxn],v; string str, ch,s1,s2; //pair <int,int> pa[mxn]; const int maxn = 1000+8; const int inf = 0x3f3f3f; int p, r, sign[maxn]; int main() { cin>>t; while(t--) { cin>>n>>m; if(m==1) cout<<1<<endl; else if(m<n) cout<<m<<endl; else if(m%n==0) cout<<(ll)n*(m/n)*(m/n)<<endl; else { ll ans = m/n; cout<<(m%n)*(ans+1)*(ans+1)+(n-m%n)*ans*ans<<endl; } } return 0; }
B. Obtain Two Zeroes
You are given two integers b. You may perform any number of operations on them (possibly zero).
During each operation you should choose any positive integer x in different operations.
Is it possible to make 0 simultaneously?
Your program should answer t independent test cases.
The first line contains one integer 1≤t≤100) — the number of test cases.
Then the test cases follow, each test case is represented by one line containing two integers 0≤a,b≤109).
For each test case print the answer to it — YES if it is possible to make NO otherwise.
You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer).
3
6 9
1 1
1 2
YES
NO
YES
In the first test case of the example two operations can be used to make both b equal to zero:
- choose b=9−8=1;
-
choose b=1−1=0.
#include <iostream> #include <algorithm> #include <cstdio> #include <string> #include <cstring> #include <cstdlib> #include <map> #include <vector> #include <set> #include <queue> #include <stack> #include <cmath> using namespace std; #define mem(s,t) memset(s,t,sizeof(s)) #define pq priority_queue #define pb push_back #define fi first #define se second #define ac return 0; #define ll long long #define cin2(a,n,m) for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) cin>>a[i][j]; #define rep_(n,m) for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) #define rep(n) for(int i=1;i<=n;i++) #define test(xxx) cout<<" Test " <<" "<<xxx<<endl; #define TLE std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cout.precision(10); #define lc now<<1 #define rc now<<1|1 #define ls now<<1,l,mid #define rs now<<1|1,mid+1,r #define half no[now].l+((no[now].r-no[now].l)>>1) #define ll long long #define mod 1000000007 const int mxn = 1e6+10; ll n,m,k,ans,col,t,flag,x,y,pim[mxn]; ll a[mxn],sum[mxn],cnt,vis[mxn]; vector<int>G[mxn],v; string str, ch,s1,s2; //pair <int,int> pa[mxn]; const int maxn = 1000+8; const int inf = 0x3f3f3f; int p, r, sign[maxn]; int main() { cin>>t; while(t--) { cin>>n>>m; if(!n&&!m) cout<<"YES"<<endl; else if( !n&& m!=0 || n!=0 && !m || m==n&&m==1 ||(n+m)%3 ) cout<<"NO"<<endl; else { if( n>=(n+m)/3 && m>=(n+m)/3 ) cout<<"YES"<<endl; else cout<<"NO"<<endl; } } return 0; }
You are a rebel leader and you are planning to start a revolution in your country. But the evil Government found out about your plans and set your punishment in the form of correctional labor.
You must paint a fence which consists of 0):
- if the index of the plank is divisible by 2r and so on) then you must paint it red;
- if the index of the plank is divisible by 2b and so on) then you must paint it blue;
- if the index is divisible both by you can choose the color to paint the plank;
- otherwise, you don't need to paint the plank at all (and it is forbidden to spent paint on it).
Furthermore, the Government added one additional restriction to make your punishment worse. Let's list all painted planks of the fence in ascending order: if there are k consecutive planks with the same color in this list, then the Government will state that you failed the labor and execute you immediately. If you don't paint the fence according to the four aforementioned conditions, you will also be executed.
The question is: will you be able to accomplish the labor (the time is not important) or the execution is unavoidable and you need to escape at all costs.
The first line contains single integer 1≤T≤1000) — the number of test cases.
The next 2≤k≤109) — the corresponding coefficients.
Print OBEY (case insensitive) otherwise.
4 1 1 2 2 10 4 5 2 3 3 2 2
OBEY REBEL OBEY OBEY
#include <iostream> #include <algorithm> #include <cstdio> #include <string> #include <cstring> #include <cstdlib> #include <map> #include <vector> #include <set> #include <queue> #include <stack> #include <cmath> using namespace std; #define mem(s,t) memset(s,t,sizeof(s)) #define pq priority_queue #define pb push_back #define fi first #define se second #define ac return 0; #define ll long long #define cin2(a,n,m) for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) cin>>a[i][j]; #define rep_(n,m) for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) #define rep(n) for(int i=1;i<=n;i++) #define test(xxx) cout<<" Test " <<" "<<xxx<<endl; #define TLE std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cout.precision(10); #define lc now<<1 #define rc now<<1|1 #define ls now<<1,l,mid #define rs now<<1|1,mid+1,r #define half no[now].l+((no[now].r-no[now].l)>>1) #define ll long long #define mod 1000000007 const int mxn = 1e6+10; ll n,m,k,ans,col,t,flag,x,y,pim[mxn]; ll a[mxn],sum[mxn],cnt,vis[mxn]; vector<int>G[mxn],v; string str, ch,s1,s2; //pair <int,int> pa[mxn]; const int maxn = 1000+8; const int inf = 0x3f3f3f; int p, r, sign[maxn]; int main() { cin>>t; while(t--) { cin>>n>>m>>k; ll gcd = __gcd(n,m) ; n/=gcd,m/=gcd; if(n>m) swap(n,m); if(m<n*(k-1)+2) cout<<"OBEY"<<endl; else cout<<"REBEL"<<endl; } return 0; }