Submission #396549

# Submission time Handle Problem Language Result Execution time Memory
396549 2021-04-30T09:31:13 Z jakubd Trol (COCI19_trol) C++14
30 / 50
1 ms 204 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

template<typename T> void ckmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void ckmax(T &a, T b) { if (a < b) a = b; }

#define pb push_back
#define mp make_pair
#define sz(x) ((int)x.size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define manytests int TT;cin >> TT; while (TT--)

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define FORd(i,a,b) for (int i = (a); i >= (b); --i)

int dx[8] = {-1, 1, 0, 0, 1, 1, -1, -1}, dy[8] = {0, 0, 1, -1, 1, 1, -1, -1};
int INF = 1e9;

#define ll long long
#define ld long double
#define fi first
#define se second
#define rev reverse

#define vi vector<int>
#define vl vector<ll>
#define vc vector<char>
#define vd vector<double>
#define vs vector<string>
#define vld vector<ld>
#define vb vector<bool>
#define vvi vector<vi>
#define pii pair<int, int>
#define pl pair<ll, ll>
#define pld pair<ld, ld>
#define vpi vector<pii>
#define vpl vector<pl>
#define vpld vector<pld>

ll sm(ll x) {
    ll r = 0;
    while (x) r += x % 10, x /= 10;
    if (r >= 10) return sm(r);
    return r;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    manytests {
        ll l, r;
        cin >> l >> r;
        ll dif = r - l + 1;
        ll i = l;
        ll ans = 0;
        while (sm(i) != 1) ans += sm(i++);
        ll p = (r - i + 1) / 9;
        ans += 45 * p;
        i += 9 * p;
        while (i <= r) ans += sm(i++);
        cout << ans << "\n";
    }

    return 0;
}

Compilation message

trol.cpp: In function 'int main()':
trol.cpp:62:12: warning: unused variable 'dif' [-Wunused-variable]
   62 |         ll dif = r - l + 1;
      |            ^~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Incorrect 1 ms 204 KB Output isn't correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct