# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
238744 |
2020-06-12T14:49:22 Z |
Halit |
Trol (COCI19_trol) |
C++17 |
|
6 ms |
384 KB |
#include <bits/stdc++.h>
using namespace std;
const bool cannot = 0;
int main(){
int q;
cin >> q;
while(q--){
long long l,r, ans = 0, sootnp, lp = 0, rp = 0, ran_l, ran_r;
cin >> l >> r;
if(r - l + 1 <= 9){
for(long long i = l;i <= r;i++)
ans += i % 9 + (i % 9 == 0) * 9;
cout << ans << "\n";
continue;
}
for(long long i = l;i <= min(r , l+9) ;i++){
if(i % 9 == 1){
ran_l = i;
break;
}
}
for(long long i = r;i >= max(l, r - 9);i--){
if(i % 9 == 1){
ran_r = i;
break;
}
}
sootnp = (ran_r - ran_l + 1) / 9 * 45;
for(long long i = l;i < ran_l;i++)
lp += i % 9 + (i % 9 == 0) * 9;
for(long long i = r;i >= ran_r;i--)
rp += i % 9 + (i % 9 == 0) * 9;
ans = sootnp + lp + rp;
cout << ans << "\n";
}
}
// ans = sum_of_one_to_nine_parts + left_part + right_part;
// sootnp starts with 1 and ends with 9
// reminders are same (1,9 -> 0) ^^^^
// for loop to find beginning and end
// sootnp = (range_length + 1) / 9 * 45
// find rigth&left_part with for
Compilation message
trol.cpp: In function 'int main()':
trol.cpp:32:19: warning: 'ran_r' may be used uninitialized in this function [-Wmaybe-uninitialized]
sootnp = (ran_r - ran_l + 1) / 9 * 45;
~~~~~~^~~~~~~
trol.cpp:32:19: warning: 'ran_l' may be used uninitialized in this function [-Wmaybe-uninitialized]
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
256 KB |
Output is correct |
3 |
Correct |
6 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
256 KB |
Output is correct |
5 |
Correct |
6 ms |
384 KB |
Output is correct |