Codeforces 라운드 # 578 (사업부. 2)

Codeforces 라운드 # 578 (사업부. 2)

A. 호텔리어

폭력이 될 수 있습니다.


암호

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5 + 5;
int n;
char s[N];
int res[10];
int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    cin >> n;
    cin >> s + 1;
    for(int i = 1; i <= n; i++) {
        if(s[i] == 'L') {
            for(int j = 0; j < 10; j++) {
                if(res[j] == 0) {
                    res[j] = 1;
                    break;
                }
            }
        } else if(s[i] == 'R') {
            for(int j = 9; j >= 0; j--) {
                if(res[j] == 0) {
                    res[j] = 1;
                    break;
                }
            }
        } else {
            res[s[i] - '0'] = 0;
        }
    }
    for(int i = 0; i < 10; i++) cout << res[i];
 
    return 0;
}

B. 블록 모험

욕심. 우리가 다음 위치로 이동 할 수있는 경우 각각의 위치를 들어, 확실히 가장 효율적으로 활용하려고 \ (블록 \) 가방에 있습니다.


암호

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5 + 5;
int t, n, m, k;
int a[N];
int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    cin >> t;
    while(t--) {
        cin >> n >> m >> k;
        for(int i = 1; i <= n; i++) cin >> a[i];
        bool ok = true;
        for(int i = 1; i < n; i++) {
            int p = max(0, a[i + 1] - k);
            if(a[i] > p) {
                m += a[i] - p;
            } else {
                if(m < p - a[i]) {
                    ok = false;
                    break;
                } else {
                    m -= p - a[i];
                }
            }
        }
        if(ok) cout << "YES" << '\n';
        else cout << "NO" << '\n';
    }
    return 0;
}

C. 라운드 복도

주문 \ (G = GCD (N-, m) \) , 후 내륜 각된다 \ (\ FRAC {N} { g} \) A, 당 외륜 \ (\ FRAC {m} { g} \) .
판사는 라인에 같은 블록 있는지 확인 후.


암호

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5 + 5;
ll n, m;
int q;
ll gcd(ll a, ll b) {
    return b == 0 ? a : gcd(b, a % b);
}
int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    cin >> n >> m >> q;
    ll g = gcd(n, m);
    ll d1 = n / g, d2 = m / g;
    while(q--) {
        ll sx, sy, ex, ey;
        cin >> sx >> sy >> ex >> ey;
        ll b1, b2;
        if(sx == 1) {
            b1 = (sy - 1) / d1;
        } else b1 = (sy - 1) / d2;
        if(ex == 1) {
            b2 = (ey - 1) / d1;
        } else b2 = (ey - 1) / d2;
        if(b1 == b2) cout << "YES" << '\n';
        else cout << "NO" << '\n';
    }
    return 0;
}

D. 화이트 라인

사각형의 왼쪽 상단 모서리로 각 위치를 열거 고려하고 답을 업데이트합니다.
이 경우는 코드와 프리픽스 정보의 일부를 유지하는 것이 필요하다 \ (합계 [I] [j는 ] \) 부 말한다 \ (J \) 시작점으로서 \을 (. 1 \) ~ \ (I \) 라인 행의 수는 조건을 충족. "상태"는 경우에 직사각형을 의미 \ ((I, J) \ ) 이 위치는 전체 라인을 염색 할 수있다.
따라서, 행에서 직접 혼돈 열거 =


암호

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2005;
int n, k;
char s[N][N];
int r[N][N], c[N][N], sum[N][N], mx[N][N];
int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    cin >> n >> k;
    for(int i = 1; i <= n; i++) {
        cin >> s[i] + 1;
        for(int j = 1; j <= n; j++) {
            r[i][j] = r[i][j - 1] + (s[i][j] == 'W');
            c[j][i] = c[j][i - 1] + (s[i][j] == 'W');
        }
    }
    int ans = 0;
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= n - k + 1; j++) {
            sum[i][j] = sum[i - 1][j];
            if(r[i][n] == n) {
                if(j == 1) ans++;
            } else if(r[i][j - 1] + r[i][n] - r[i][j + k - 1] == n - k) sum[i][j]++;
        }
    }
    for(int i = 1; i <= n - k + 1; i++) {
        for(int j = 1; j <= n - k + 1; j++) {
            mx[i][j] = sum[i + k - 1][j] - sum[i - 1][j];
        }
    }
    memset(sum, 0, sizeof(sum));
    for(int j = 1; j <= n; j++) {
        for(int i = 1; i <= n - k + 1; i++) {
            sum[i][j] = sum[i][j - 1];
            if(c[j][n] == n) {
                if(i == 1) ans++;
            } else if(c[j][i - 1] + c[j][n] - c[j][i + k - 1] == n - k) sum[i][j]++;
        }
    }
    int res = 0;
    for(int i = 1; i <= n - k + 1; i++) {
        for(int j = 1; j <= n - k + 1; j++) {
            res = max(res, mx[i][j] + sum[i][j + k - 1] - sum[i][j - 1]);
        }
    }
    ans += res;
    cout << ans;
    return 0;
}

E. 압축 단어

우리가 지금 응답 문자열이 있다고 가정 \ (RES는 \) , 지금 다시 와서 \ (S \) 그것으로 접합 문자열을 분석하기 쉽습니다 \ (RES \) 문자열까지 사용 \ (분 (len_ {고해상도를} , len_ {S}) \) 길이. 그래서 우리는 그의 등을 수행하기 위해이 부분을 제거합니다.
직접 확장에 \ (KMP의 \) , 당신은 또한 사용할 수 있습니다 \ (KMP \) . 다이렉트 \는 (KMP는 \) , 먼저 획득 \ (S \) 문자열 \ (다음 \)를 다음 \ (RES \) 문자열 후방 부 (상정 될 \ (TMP \) 문자열)의 매칭 (\ TMP \) 시간의 끝은 \ (S \) 긴 후방 결정 프리픽스 문자열을 매치.


암호

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e6 + 5;
int n;
int Next[N];
int KMP(string &s, string &t) {
    int lens = s.length(), lent = t.length();
    Next[0] = -1;
    int j = -1;
    for(int i = 1; i < lent; i++) {
        while(j >= 0 && t[i] != t[j + 1]) j = Next[j];
        if(t[i] == t[j + 1]) j++;
        Next[i] = j;
    }
    int len = min(lent, lens);
    j = -1;
    for(int i = lens - len; i < lens; i++) {
        while(j >= 0 && (j == lent - 1 || s[i] != t[j + 1])) j = Next[j];
        if(s[i] == t[j + 1]) j++;
    }
    return j;
}
string s, res;
int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    cin >> n >> s;
    res = s;
    for(int i = 2; i <= n; i++) {
        cin >> s;
        int p = KMP(res, s);
        res += s.substr(p + 1);
    }
    cout << res;
    return 0;
}

추천

출처www.cnblogs.com/heyuhhh/p/11348458.html