2023-2024 CTU Open Contest

A. Beth's Cookies

n = int(input())
s = input()
res = []
for i in s :
    if res == []:
        res.append(i)
    elif  i == '(':
        if res[-1] == ')':
            res.append("*")
        res.append(i)
    else :
        if( res[-1] == ')' ):
            res.append("+1")
        else :
            res.append("1")
        res.append(i)
res = "".join(res)
print(eval(res))

D. Expressions

#include <bits/stdc++.h>

using namespace std;

#define int long long
using i32 = int32_t;
using vi = vector<int>;
using pii = pair<int, int>;

using node = bitset<21>;



i32 main() {
    int n , m , res = 0;
    cin >> n >> m;

    string opt;
    vi a(n) , pos(n) , cnt(1);
    cin >> a[0] , a[0] %= 2 , cnt[0] = (a[0] == 0);
    for( int i = 1 , p = 0 , x ; i < n ; i ++ ){
        cin >> opt >> x , x %= 2;
        if( opt == "+" or opt == "-" ) p ++ , cnt.push_back(0);
        a[i] = x ,pos[i] = p , cnt[p] += (x == 0);
    }

    for( auto i : cnt )
        if( i == 0 ) res ^= 1;

    vector<string> S = { "even\n" , "odd\n"};
    cout << S[res];
    for( int x , y ; m ; m -- ){
        cin >> x >> y , x -- , y %= 2;
        if( y != a[x] ){
            if( a[x] == 1 ) {
                if( ++ cnt[pos[x]] == 1) res ^= 1;
            }
            else {
                if( -- cnt[pos[x]] == 0 ) res ^= 1;
            }
            a[x] = y;
        }
        cout << S[res];
    }
    return 0;
}

F. Golem Coordinated Derby

#include <bits/stdc++.h>

using namespace std;

#define int long long
using i32 = int32_t;
using vi = vector<int>;
using pii = pair<int, int>;

using node = bitset<21>;

i32 main() {
    int n , ans = 0;
    cin >> n;
    node t;
    for (int i = 1, x; i <= n; i++) {
        cin >> x;
        if (t[x] == 1) ans += x;
        else t[x] = 1;
    }
    vi a(1);
    int m = 0;
    for (int i = 1; i <= 20; i++)
        if (t[i]) a.push_back(i), m++;

    vector<vi> d(m + 1, vi(m + 1));
    for (int i = 1; i <= m; i++)
        for (int j = 1; j < i; j++)
            d[i][j] = d[j][i] = __gcd(a[i], a[j]);

    int V = 1 << m;
    vector<vi> f(m + 1, vi(V));

    vector<vi> cnt(m + 1);
    for (int i = 1, x, y; i < V; i++) {
        x = i , y = 0;
        while (x) y++, x -= (x & -x);
        cnt[y].push_back(i);
    }

    vi T(m + 1);
    for (int i = 1; i <= m; i++)
        T[i] = 1 << (i - 1);

    for (auto it: cnt) {
        for (auto v: it) {
            for (int i = 1; i <= m; i++) {
                if ((v & T[i]) == 0) continue;
                for (int j = 1; j <= m; j++) {
                    if (i == j or (v & T[j]) == 0) continue;
                    f[i][v] = max( f[i][v] , f[j][ v ^ T[i] ] + d[i][j] );
                }
            }
        }
    }
    int res = 0;
    for( auto i = 1 ; i <= m ; i ++ )
        res = max( res , *max_element(f[i].begin(), f[i].end() ));
    cout << res + ans<< "\n";
    return 0;
}

I. Natatorium

#include <bits/stdc++.h>

using namespace std;

#define int long long
using i32 = int32_t;
using vi = vector<int>;
using pii = pair<int,int>;

i32 main(){
    int C , n;
    cin >> C >> n;
    vi a(n);
    set<int> b;
    for ( auto & i : a )
        cin >> i , b.insert(i);
    for( int j ; auto i : a ){
        if( C % i ) continue;
        j = C / i;
        if( i == j ) continue;
        if( b.count(j) ){
            cout << min( i , j ) << " " << max( i , j ) << "\n";
            return 0;
        }
    }
    return 0;
}

J. Proglute

#include <bits/stdc++.h>

using namespace std;

#define int long long
using i32 = int32_t;
using vi = vector<int>;
using pii = pair<int,int>;

const int mod = 1e9+7;

int power( int x , int y ){
    int ans = 1;
    while( y ){
        if( y & 1 ) ans = ans * x % mod;
        x = x * x % mod , y /= 2;
    }
    return ans;
}

i32 main(){
    int n;
    cin >> n;
    if( n == 2 ){
        cout << 1 << "\n";
        return 0;
    }
    n -= 2;
    cout << ( n + 2) * power( 2 , n - 1 ) % mod;
    return 0;
}

L. Wall

#include <bits/stdc++.h>

using namespace std;

#define int long long
using i32 = int32_t;
using vi = vector<int>;
using pii = pair<int,int>;

i32 main(){
    int R , k;
    cin >> R >> k;
    vi T(8);

    for( auto &i : T )
        i = R&1 , R >>= 1;
    string s , t;
    cin >> s;
    int n = s.size();
    vector<int> a(n+2) , b(n+2);

    for( int i = 1 ; i <= n ; i ++ )
        a[i] = s[i-1] == 'X';

    for( ; k ; k -- ){
        for( int i = 1 , x ; i <= n ; i ++ ){
            x =  a[i-1] * 4 + a[i] * 2 + a[i+1];
            b[i] = T[x];
        }
        swap( a , b);
        for( int i = 1 ; i <= n ; i ++ )
            cout << ".X"[ a[i] ];
        cout << "\n";
    }
    return 0;
}
posted @ 2023-12-04 14:21  PHarr  阅读(62)  评论(0编辑  收藏  举报