Educational Codeforces Round 98 (Rated for Div. 2)
A. Robot Program
#include <bits/stdc++.h>
#define int ll
using namespace std;
typedef long long ll;
const int maxn= 2e5 + 5 ;
void solve ( ) {
int x, y;
cin>> x>> y;
cout<< max ( x, y) * 2 - ( x!= y) << "\n" ;
}
signed main ( ) {
ios:: sync_with_stdio ( false ) ; cin. tie ( 0 ) ; cout. tie ( 0 ) ;
int _ = 1 ;
cin >> _;
while ( _-- ) {
solve ( ) ;
}
return 0 ;
}
B. Toy Blocks
#include <bits/stdc++.h>
#define int ll
using namespace std;
typedef long long ll;
const int maxn= 2e5 + 5 ;
void solve ( ) {
int n, x, sum= 0 , max_= 0 ;
cin>> n;
for ( int i= 0 ; i< n; i++ )
cin>> x, sum+ = x, max_= max ( max_, x) ;
cout<< max ( max_* ( n- 1 ) - sum, sum% ( n- 1 ) ? n- 1 - sum% ( n- 1 ) : 0 ) << "\n" ;
}
signed main ( ) {
ios:: sync_with_stdio ( false ) ; cin. tie ( 0 ) ; cout. tie ( 0 ) ;
int _ = 1 ;
cin >> _;
while ( _-- ) {
solve ( ) ;
}
return 0 ;
}
C. Two Brackets
#include <bits/stdc++.h>
#define int ll
using namespace std;
typedef long long ll;
const int maxn= 2e5 + 5 ;
stack< int > a, b;
void solve ( ) {
while ( ! a. empty ( ) ) a. pop ( ) ;
while ( ! b. empty ( ) ) b. pop ( ) ;
string s;
cin>> s;
int sum= 0 ;
for ( int i= 0 ; i< s. size ( ) ; i++ ) {
if ( s[ i] == '(' ) a. push ( 1 ) ;
if ( s[ i] == '[' ) b. push ( 1 ) ;
if ( s[ i] == ')' && ! a. empty ( ) ) sum++ , a. pop ( ) ;
if ( s[ i] == ']' && ! b. empty ( ) ) sum++ , b. pop ( ) ;
}
cout << sum<< "\n" ;
}
signed main ( ) {
ios:: sync_with_stdio ( false ) ; cin. tie ( 0 ) ; cout. tie ( 0 ) ;
int _ = 1 ;
cin >> _;
while ( _-- ) {
solve ( ) ;
}
return 0 ;
}
D. Radio Towers
#include <bits/stdc++.h>
#define int ll
using namespace std;
typedef long long ll;
const int maxn= 2e5 + 5 ;
const int mod= 998244353 ;
int f[ maxn] ;
void init ( ) {
f[ 0 ] = 0 ; f[ 1 ] = 1 ;
for ( int i = 2 ; i < maxn; ++ i)
f[ i] = ( f[ i- 1 ] + f[ i- 2 ] ) % mod;
}
int fastpow ( int a, int n) {
int res= 1 , temp= a;
while ( n) {
if ( n& 1 ) res= res* temp% mod;
temp= temp* temp% mod;
n>>= 1 ;
}
return res;
}
void solve ( ) {
int n;
cin>> n;
cout<< f[ n] * fastpow ( fastpow ( 2 , n) , mod- 2 ) % mod;
}
signed main ( ) {
ios:: sync_with_stdio ( false ) ; cin. tie ( 0 ) ; cout. tie ( 0 ) ;
int _ = 1 ;
cin >> _; init ( ) ;
while ( _-- ) {
solve ( ) ;
}
return 0 ;
}