COFO::Round #609 ( div 2 )

Problem A : Equation

Point

Design(x)

Big O(time)

Big O(memory)

Code(x)

#include<bits/stdc++.h>
#define endl '\n'
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;i++)
#define r_rep(i,a,b) for(int i=a;i>b;i--)
const int MAXN = 200 * 1000 * 1000 + 1;
using namespace std;
bool era[MAXN];
void precalc(){
    memset(era, true, sizeof(era));
    for(int i=2; i * i <= MAXN; i++){
        if(era[i]){
            for(int j = i+i; j <= MAXN; j+=i){
                era[j] = false;
            }
        }
    }
}
void process(){
    precalc();
    int n; cin >> n;
    if(n%2 == 0){
        if(n == 2) cout << "6 4" << endl;
        else cout << n+4<<" 4" << endl;
    }else{
        for(int a = n+4; a < MAXN; a += 2)
            if(!era[a]){
                cout << a << " " << a-n << endl;
                return;
            }
    }
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    process();
    return 0;
}

Problem B : Modulo Equality

Point

Design(x)

Big O(time)

Big O(memory)

Code(x)

#include<bits/stdc++.h>
#define endl '\n'
//#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;i++)
#define r_rep(i,a,b) for(int i=a;i>b;i--)
const int MAXN = 2000+1;
typedef long long ll;
using namespace std;

ll n, mod;
ll cnta, cntb;
map<ll,ll> mpa, mpb;
pair<ll,ll> pa[MAXN], pb[MAXN];
void input(){
    ll x;
    cin >> n >> mod;
    rep(i, 0, n){ cin >> x; mpa[x]++; }
    rep(i, 0, n){ cin >> x; mpb[x]++; }
    for(auto y : mpa) pa[cnta++] = {y.first, y.second};
    for(auto y : mpb) pb[cntb++] = {y.first, y.second};
}
void process(){
    input();
    vector<ll> ans;
    int sta = 0;
    for(int stb = 0; stb < cntb; stb++, sta = 0){
        int i = sta;
        int j = stb;
        bool found = true;
        for(int cnt = 0; cnt < cntb; cnt++){
            if(pa[i].second != pb[j].second){
                found = false;
                break;
            }
            i++; j = (j+1) % cntb;
        }
        if(found){
            int l = sta, k = stb;
            ll gap = (pb[stb].first - pa[sta].first + mod) %mod;
            for(int cnt = 0; cnt < cntb; cnt++){
                if((pa[l].first + gap) % mod != pb[k].first){
                    found = false;
                    break;
                }
                l++; k = (k+1) % cntb;
            }
            if(found){
                ans.push_back(gap);
//                cout << gap << endl;
//                return;
            }
        }
    }
    sort(ans.begin(), ans.end());
    cout << ans[0] << endl;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    process();
    return 0;
}

Problem C : Long Beautiful Integer

Point

Design(x)

Big O(time)

Big O(memory)

Code(x)

#include<bits/stdc++.h>
#define endl '\n'
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;i++)
#define r_rep(i,a,b) for(int i=a;i>b;i--)
using namespace std;
void process(){
    int n, k; cin >> n >> k;
    string a, ans; cin >> a;
    rep(i, 0, n) ans += a[i%k];
    if(a > ans){
        r_rep(i, k-1, -1){
            if(ans[i] < '9'){
                ans[i]++;
                break;
            }else ans[i] = '0';
        }
        rep(i, 0, n) ans[i] = ans[i%k];
    }
    cout << n << endl;
    cout << ans << endl;

}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    process();
    return 0;
}