abc178_a - Not

Click to show code.


using namespace std;
using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;
int main(void)
{
    bool x;
    cin >> x;
    cout << not x << endl;
    return 0;
}


abc175_d - Moving Piece

Click to show code.


using namespace std;
using ll = long long;
int const NMAX = 3000 + 5;
ll const INF = 1e16;
ll n, m, k, dp[NMAX][NMAX][4], v[NMAX][NMAX];
ll solve(void)
{
    for (int c = 1; c <= m; ++c)
        fill(dp[0][c], dp[0][c] + 4, -INF);
    for (int r = 1; r <= n; ++r)
        fill(dp[r][0], dp[r][0] + 4, -INF);
    fill(dp[1][0], dp[1][0] + 4, 0);
    fill(dp[0][1], dp[0][1] + 4, 0);
    for (int r = 1; r <= n; ++r)
    {
        for (int c = 1; c <= m; ++c)
        {
            for (int cap = 0; cap <= 3; ++cap)
            {
                auto &ans = dp[r][c][cap];
                ans = max(dp[r - 1][c][3], dp[r][c - 1][cap]);
                if (cap > 0)
                {
                    ans = max({ans,
                               dp[r - 1][c][3] + v[r][c],
                               dp[r][c - 1][cap - 1] + v[r][c]});
                }
            }
        }
    }
    return *max_element(dp[n][m], dp[n][m] + 4);
}
int main(void)
{
    int ri, ci;
    cin >> n >> m >> k;
    for (int i = 1; i <= k; ++i)
    {
        cin >> ri >> ci;
        cin >> v[ri][ci];
    }
    cout << solve() << endl;
    return 0;
}


abc175_c - Walking Takahashi

Click to show code.


using namespace std;
using ll = long long;
int main(void)
{
    ll x, k, d;
    cin >> x >> k >> d;
    x = abs(x);
    if (x / d <= k)
    {
        k -= x / d;
        x -= (x / d) * d;
        if (k % 2 == 1)
            x -= d;
    }
    else
    {
        x -= k * d;
        k -= k;
    }
    cout << abs(x) << endl;
    return 0;
}


abc175_b - Making Triangle

Click to show code.


using namespace std;
using ll = long long;
using vi = vector<int>;
bool is_valid(int a, int b, int c)
{
    if (a + b <= c or a + c <= b or b + c <= a)
        return false;
    else
        return true;
}
int main(void)
{
    int n;
    vi l;
    cin >> n;
    l.resize(n);
    for (auto &li : l)
        cin >> li;
    sort(l.begin(), l.end());
    ll ans = 0;
    for (int i = 0; i < n - 2; ++i)
    {
        for (int j = i + 1; j < n - 1; ++j)
        {
            for (int k = j + 1; k < n; ++k)
            {
                if (l[i] == l[j] or l[i] == l[k] or l[j] == l[k])
                    continue;
                bool cur = is_valid(l[i], l[j], l[k]);
                ans += cur;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


abc175 - Rainy Season

Click to show code.


using namespace std;
int main(void)
{
    string s;
    cin >> s;
    int ans = 0, cnt = 0;
    for (auto c : s)
    {
        if (c == 'R')
            ++cnt;
        else
        {
            ans = max(cnt, ans);
            cnt = 0;
        }
    }
    ans = max(cnt, ans);
    cout << ans << endl;
    return 0;
}


abc174_e - Logs

Click to show code.


using namespace std;
using ll = long long;
using vi = vector<int>;
using predicate = function<bool(int)>;
const int AMAX = 1e9 + 11;
int n, k;
vi a;
bool is_possible(int l)
{
    ll c = 0;
    for (int x : a)
        c += (x - 1) / l;
    return c <= k;
}
ll bsearch(ll l, ll r, predicate p)
{
    while (l < r)
    {
        ll m = l + (r - l) / 2;
        if (p(m))
            r = m;
        else
            l = m + 1;
    }
    return l;
}
int main(void)
{
    cin >> n >> k;
    a.resize(n);
    for (auto &x : a)
        cin >> x;
    cout << bsearch(1, AMAX, is_possible) << endl;
    return 0;
}


abc174_d - Alter Altar

Click to show code.


using namespace std;
int solve(int n, string &s)
{
    int l, r, ans = 0;
    l = 0, r = n - 1;
    while (l < r)
    {
        while (l < n and s[l] != 'W')
            ++l;
        while (r >= 0 and s[r] != 'R')
            --r;
        if (l >= r)
            break;
        swap(s[l], s[r]);
        ++ans;
    }
    return ans;
}
int main(void)
{
    int n;
    string s;
    cin >> n;
    cin >> s;
    cout << solve(n, s) << endl;
    return 0;
}


abc174_c - Repsept

Click to show code.


using namespace std;
using ll = long long;
int solve(int k)
{
    ll n = 7;
    for (ll i = 1; i <= k; ++i)
    {
        ll m = n % k;
        if (m == 0)
            return i;
        n = n * 10 + 7;
        n %= k;
    }
    return -1;
}
int main(void)
{
    int k;
    cin >> k;
    cout << solve(k) << endl;
    return 0;
}


abc174_b - Distance

Click to show code.


using namespace std;
using ll = long long;
int main(void)
{
    ll n, x, y, ans = 0;
    double d;
    cin >> n >> d;
    for (int i = 0; i < n; ++i)
    {
        cin >> x >> y;
        double cur_dist = sqrt(x * x + y * y);
        if (cur_dist <= d)
            ans++;
    }
    cout << ans << endl;
    return 0;
}


abc174_a - Air Conditioner

Click to show code.


using namespace std;
int main(void)
{
    int x;
    cin >> x;
    cout << (x >= 30 ? "Yes" : "No") << endl;
    return 0;
}