其他分享
首页 > 其他分享> > Codeforces Round #578 (Div. 2)

Codeforces Round #578 (Div. 2)

作者:互联网

Codeforces Round #578 (Div. 2)

A. Hotelier


#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

ll mult_mod(ll x, ll y, ll mod){
    return (x * y - (ll)(x / (long double)mod * y + 1e-3) * mod + mod) % mod;
}

ll pow_mod(ll a, ll b, ll p){
    ll res = 1;
    while (b){
        if (b & 1)
            res = mult_mod(res, a, p);
        a = mult_mod(a, a, p);
        b >>= 1;
    }
    return res % p;
}

ll gcd(ll a, ll b){
    return b ? gcd(b, a % b) : a;
}

int n;
string s;
int a[10];

int main(){
#ifndef ONLINE_JUDGE
    freopen("my_in.txt", "r", stdin);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> s;
    for (auto x: s){
        if (x == 'L'){
            for (int i = 0; i < 10; i ++ ){
                if (!a[i]){
                    a[i] = 1;
                    break;
                }
            }
        }
        else if (x == 'R'){
            for (int i = 9; i >= 0; i -- ){
                if (!a[i]){
                    a[i] = 1;
                    break;
                }
            }
        }
        else
            a[x - '0'] = 0;
    }
    for (int i = 0; i < 9; i ++ )
        cout << a[i];
    cout << a[9] << "\n";
    return 0;
}

B. Block Adventure


#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

ll mult_mod(ll x, ll y, ll mod){
    return (x * y - (ll)(x / (long double)mod * y + 1e-3) * mod + mod) % mod;
}

ll pow_mod(ll a, ll b, ll p){
    ll res = 1;
    while (b){
        if (b & 1)
            res = mult_mod(res, a, p);
        a = mult_mod(a, a, p);
        b >>= 1;
    }
    return res % p;
}

ll gcd(ll a, ll b){
    return b ? gcd(b, a % b) : a;
}

const int N = 110;

int t, n, m, k;
int h[N];

int main(){
#ifndef ONLINE_JUDGE
    freopen("my_in.txt", "r", stdin);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> t;
    while (t -- ){
        cin >> n >> m >> k;
        for (int i = 1; i <= n; i ++ )
            cin >> h[i];
        for (int i = 1; i < n; i ++ ){
            int x = min(h[i], h[i] - (h[i + 1] - k));
            m += x;
            if (m < 0)
                break;
        }
        if (m < 0)
            cout << "NO\n";
        else
            cout << "YES\n";
    }
    return 0;
}

C. Round Corridor


#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

ll mult_mod(ll x, ll y, ll mod){
    return (x * y - (ll)(x / (long double)mod * y + 1e-3) * mod + mod) % mod;
}

ll pow_mod(ll a, ll b, ll p){
    ll res = 1;
    while (b){
        if (b & 1)
            res = mult_mod(res, a, p);
        a = mult_mod(a, a, p);
        b >>= 1;
    }
    return res % p;
}

ll gcd(ll a, ll b){
    return b ? gcd(b, a % b) : a;
}

ll  n, m, q, gcd_, sx, sy, ex, ey;

ll  calc(ll  x, ll  y){
    if (x == 1)
        return y / (n / gcd_);
    return y / (m / gcd_);
}

int main(){
#ifndef ONLINE_JUDGE
    freopen("my_in.txt", "r", stdin);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> m >> q;
    gcd_ = gcd(n, m);
    while (q -- ){
        cin >> sx >> sy >> ex >> ey;
        // cout << calc(sx, sy - 1) << " " << calc(ex, ey - 1) << "\n";
        if (calc(sx, sy - 1) == calc(ex, ey - 1))
            cout << "YES\n";
        else
            cout << "NO\n";
    }
    return 0;
}

D. White Lines


#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

ll mult_mod(ll x, ll y, ll mod){
    return (x * y - (ll)(x / (long double)mod * y + 1e-3) * mod + mod) % mod;
}

ll pow_mod(ll a, ll b, ll p){
    ll res = 1;
    while (b){
        if (b & 1)
            res = mult_mod(res, a, p);
        a = mult_mod(a, a, p);
        b >>= 1;
    }
    return res % p;
}

ll gcd(ll a, ll b){
    return b ? gcd(b, a % b) : a;
}

const int N = 2010;

int n, k, ans, res;
int x[N][N], y[N][N], cnt_x[N][N], cnt_y[N][N], sum_x[N][N], sum_y[N][N];

int main(){
#ifndef ONLINE_JUDGE
    freopen("my_in.txt", "r", stdin);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> k;
    for (int i = 1; i <= n; i ++ ){
        string s;
        cin >> s;
        for (int j = 1; j <= n; j ++ ){
            cnt_x[i][j] = cnt_x[i - 1][j] + (s[j - 1] == 'B');
            cnt_y[i][j] = cnt_y[i][j - 1] + (s[j - 1] == 'B');
        }
    }
    for (int i = 1; i <= n; i ++ )
        for (int j = 1; j <= n - k + 1; j ++ )
            if (cnt_y[i][n] && cnt_y[i][j + k - 1] - cnt_y[i][j - 1] == cnt_y[i][n])
                y[i][j] = 1;
    for (int i = 1; i <= n - k + 1; i ++ )
        for (int j = 1; j <= n; j ++ )
            if (cnt_x[n][j] && cnt_x[i + k - 1][j] - cnt_x[i - 1][j] == cnt_x[n][j])
                x[i][j] = 1;
    for (int i = 1; i <= n; i ++ ){
        for (int j = 1; j <= n; j ++ ){
            sum_x[i][j] = sum_x[i][j - 1] + x[i][j];
            sum_y[i][j] = sum_y[i - 1][j] + y[i][j];
        }
    }
    for (int i = 1; i <= n - k + 1; i ++ )
        for (int j = 1; j <= n - k + 1; j ++ )
            ans = max(ans, sum_x[i][j + k - 1] - sum_x[i][j - 1] + sum_y[i + k - 1][j] - sum_y[i - 1][j]);
    for (int i = 1; i <= n; i ++ )
        res += (cnt_x[n][i] == 0) + (cnt_y[i][n] == 0);
    // cout << ans << " " << res << "\n";
    cout << ans + res << "\n";
    return 0;
}

E. Compress Words


#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

ll mult_mod(ll x, ll y, ll mod){
    return (x * y - (ll)(x / (long double)mod * y + 1e-3) * mod + mod) % mod;
}

ll pow_mod(ll a, ll b, ll p){
    ll res = 1;
    while (b){
        if (b & 1)
            res = mult_mod(res, a, p);
        a = mult_mod(a, a, p);
        b >>= 1;
    }
    return res % p;
}

ll gcd(ll a, ll b){
    return b ? gcd(b, a % b) : a;
}

int n, len, len_;
string s, t;

void get_nxt(string s, int *nxt){
    int j, k;
    nxt[0] = -1;
    j = 0, k = -1;
    while (j < len_){
        if (k == -1 || s[j] == s[k]){
            j ++ , k ++ ;
            nxt[j] = k;
        }
        else
            k = nxt[k];
    }
}

int kmp(string s, string t){
    int nxt[len_ + 1];
    int i, j;
    i = j = 0;
    get_nxt(t, nxt);
    while (i < s.length()){
        if (j == -1 || s[i] == t[j])
            i ++ , j ++ ;
        else
            j = nxt[j];
        if (j == len_)
            return len_;
    }
    return j;
}

int main(){
#ifndef ONLINE_JUDGE
    freopen("my_in.txt", "r", stdin);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    cin >> s;
    for (int i = 2; i <= n; i ++ ){
        cin >> t;
        len = s.length(), len_ = t.length();
        int len__ = max(0, len - len_);
        int tmp = kmp(s.substr(len__), t);
        for (int j = tmp; j < len_; j ++ )
            s += t[j];
    }
    cout << s << "\n";
    return 0;
}

标签:578,int,res,ll,Codeforces,long,Div,include,mod
来源: https://www.cnblogs.com/Misuchii/p/13917442.html