답안 #218199

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
218199 2020-04-01T13:25:43 Z maskoff Trol (COCI19_trol) C++14
10 / 50
1000 ms 384 KB
#include <bits/stdc++.h>
#include <ext/rope>
 
#define file ""
 
#define all(x) x.begin(), x.end()
 
#define sc second
#define fr first
 
#define pb push_back
#define mp make_pair
 
using namespace std;
using namespace __gnu_cxx;
 
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll; 

const int inf = 1e9;
const int MOD = 998244353;
const int N = 5e5;
                                          
const int dx[] = {+1, -1, 0, 0};
const int dy[] = {0, 0, +1, -1};

ll sum(ll x) {
	ll res = 0;
	while (x) {
	 	res += x % 10;
	 	x /= 10 ;
	}
	return res;
}

ll get(ll x) {
	while (x >= 10) {
	 	x = sum(x);
	}
	return x;
}


int main() {                                
  ios_base :: sync_with_stdio(false);
  cin.tie(NULL);
  srand(time(NULL));
  int q;
  cin >> q;
  while (q--) {
   	ll l, r;
   	cin >> l >> r;
   	ll ans = (r - l + 1) / 9;
   	ans *= 45;
   	if (ans == 0) {
   	 	for (int i = l; i <= r; i++)
   	 		ans += get(i);
   	 	cout << ans << endl;
   		continue;
   	}
   	l = get(l);
   	r = get(r);
   	if (l != 1)
   		for (int i = l; i <= 9; i++)
   			ans += i;
   	if (r != 9)
   		for (int i = 1; i <= r; i++)
   			ans += i;
   			
   	cout << ans << endl;
  }
	return 0;                   
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Incorrect 5 ms 384 KB Output isn't correct
3 Execution timed out 1095 ms 384 KB Time limit exceeded
4 Incorrect 5 ms 384 KB Output isn't correct
5 Incorrect 5 ms 384 KB Output isn't correct