abc173_c - H And V

Click to show code.


using namespace std;
int count_black(
    const vector<string> &color, int mask_h, int mask_w, int h, int w)
{
    int ans = 0;
    for (int r = 0; r < h; ++r)
    {
        for (int c = 0; c < w; ++c)
        {
            if (((mask_h >> r) & 1) or (mask_w >> c) & 1)
                continue;
            if (color[r][c] == '#')
                ans++;
        }
    }
    return ans;
}
int main(void)
{
    int h, w, k, ans = 0;
    vector<string> c;
    cin >> h >> w >> k;
    c.resize(h);
    for_each(c.begin(), c.end(), [](string &row) { cin >> row; });
    for (int mask_h = 0; mask_h < (1 << h); ++mask_h)
    {
        for (int mask_w = 0; mask_w < (1 << w); ++mask_w)
        {
            if (auto cur = count_black(c, mask_h, mask_w, h, w); cur == k)
                ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


abc173_b - Judge Status Summary

Click to show code.


using namespace std;
int main(void)
{
    int n;
    string stat;
    map<string, int> counter;
    cin >> n;
    while (n--)
    {
        cin >> stat;
        counter[stat]++;
    }
    cout << "AC x " << counter["AC"] << endl;
    cout << "WA x " << counter["WA"] << endl;
    cout << "TLE x " << counter["TLE"] << endl;
    cout << "RE x " << counter["RE"] << endl;
    return 0;
}


abc173_a - Payment

Click to show code.


using namespace std;
int main(void)
{
    int n;
    cin >> n;
    cout << (1000 - (n % 1000)) % 1000 << endl;
    return 0;
}


abc172_d - Sum Of Divisors

Click to show code.


using namespace std;
using ll = long long;
int const NMAX = 1e7 + 11;
int f[NMAX];
int main(void)
{
    int n;
    cin >> n;
    fill(f, f + n + 1, 2);
    f[1] = 1;
    for (ll i = 2; i <= n; ++i)
    {
        for (ll j = i; j * i <= n; ++j)
        {
            if (i == j)
                f[i * j] += 1;
            else
                f[i * j] += 2;
        }
    }
    ll ans = 0;
    for (ll i = 1; i <= n; ++i)
    {
        ans += i * f[i];
    }
    cout << ans;
    return 0;
}


abc172_c - Tsundoku

Click to show code.


using namespace std;
using ll = long long;
int const NMAX = 2e5 + 11;
int n, m;
ll k, pa[NMAX], pb[NMAX];
int main(void)
{
    int ai, bi;
    cin >> n >> m >> k;
    for (int i = 1; i <= n; ++i)
        cin >> ai, pa[i] = ai + pa[i - 1];
    for (int i = 1; i <= m; ++i)
        cin >> bi, pb[i] = bi + pb[i - 1];
    int ans = 0, j;
    for (int i = 0; i <= n; ++i)
    {
        if (k - pa[i] < 0)
            break;
        auto match = prev(upper_bound(pb + 1, pb + m + 1, k - pa[i]));
        j = distance(pb, match);
        ans = max(ans, i + j);
    }
    cout << ans << endl;
    return 0;
}


abc172_b - Minor Change

Click to show code.


using namespace std;
int main(void)
{
    int ans = 0;
    string s, t;
    cin >> s >> t;
    for (int i = 0, n = s.size(); i < n; ++i)
    {
        ans += (s[i] != t[i]);
    }
    cout << ans << endl;
    return 0;
}


abc172_a - Calc

Click to show code.


using namespace std;
int main(void)
{
    int a0, a1;
    cin >> a0;
    a1 = a0 * a0;
    cout << a0 * (1 + a0 + a1) << endl;
    return 0;
}


abc171_e - Red Scarf

Click to show code.


using namespace std;
using vi = vector<int>;
int main(void)
{
    int n, sum;
    vi a;
    cin >> n;
    sum = 0;
    a.resize(n);
    for (auto &ai : a)
    {
        cin >> ai;
        sum ^= ai;
    }
    for (auto ai : a)
        cout << (ai ^ sum) << " ";
    cout << endl;
    return 0;


abc171_d - Replacing

Click to show code.


using namespace std;
using ll = long long;
int const AMAX = 1e5 + 11;
ll freq[AMAX], sum;
void update(ll b, ll c)
{
    sum -= b * freq[b];
    sum += freq[b] * c;
    freq[c] += freq[b];
    freq[b] = 0;
}
inline ll query(void) { return sum; }
int main(void)
{
    int n, q, ai, b, c;
    cin >> n;
    sum = 0;
    for (int i = 0; i < n; ++i)
    {
        cin >> ai;
        freq[ai]++;
        sum += ai;
    }
    cin >> q;
    while (q--)
    {
        cin >> b >> c;
        update(b, c);
        cout << query() << endl;
    }
    return 0;
}


abc171_c - One Quadrillion And One Dalmatians

Click to show code.


using namespace std;
using ll = long long;
int main(void)
{
    ll n;
    char c;
    string s;
    cin >> n;
    while (n > 0)
    {
        n -= 1;
        c = 'a' + (n % 26LL);
        s = c + s;
        n /= 26LL;
    };
    cout << s << endl;
    return 0;
}