답안 #976271

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
976271 2024-05-06T11:25:48 Z vjudge1 Trol (COCI19_trol) C++17
30 / 50
1000 ms 348 KB
#include <bits/stdc++.h>
#define bismillah ios_base::sync_with_stdio(0); cin.tie(0);
#define int 		  long long
#define v 			  vector
#define pb 			  push_back
#define ppb 		  pop_back
#define all(x)    x.begin(), x.end()
#define rall(x)   x.begin(), x.end()
#define pii 		  pair<int, int>
#define pll 		  pair<long long, long long>
#define fi 			  first
#define se 			  second
#define mp 			  make_pair
#define lb 			  lower_bound
#define ub 			  upper_bound
#define endl 		  '\n'
#define tc 			  int t = 1; while (t--)
// #define tc 			  int t; cin >> t; while (t--)
const int MOD = 1e9 + 7;
const int INF = 1e17;
using namespace std;

int compress(int x) {
	if (x < 10)
		return x;
	
	int sum_digs = 0;
	while (x) {
		sum_digs += x % 10;
		x /= 10;
	}
	
	return compress(sum_digs);
}

signed main(){
	bismillah;
	tc {
		//input
		int q; cin >> q;
		
		//solve
		//output
		while (q--) {
			int l, r;
			cin >> l >> r;
			int ans = 0;
			for (int i = l; i <= r; i++) {
				ans += compress(i);
			}
			cout << ans << endl;
		}
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 2 ms 348 KB Output is correct
4 Execution timed out 1077 ms 348 KB Time limit exceeded
5 Execution timed out 1063 ms 348 KB Time limit exceeded