Submission #976287

# Submission time Handle Problem Language Result Execution time Memory
976287 2024-05-06T11:39:20 Z vjudge1 Trol (COCI19_trol) C++17
10 / 50
3 ms 2140 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int maxn=1e5;
int arr[maxn];
void buat1(int &n){
	int sum=0;
	while(n!=0){
	sum= sum+ (n%10);
	n/=10;
}
n=sum;

}
void pre_compute(){
	for(int i=0; i<=maxn; i++){	
	int keepi=i;
	while(keepi - 10 >= 0){
	buat1(keepi);
	}arr[i] = keepi;
}
	
}
signed main(){
memset(arr,0,sizeof(arr));
pre_compute();

	int q;
	cin >> q;
	while(q--){
		int l,r;
		cin >> l>> r;
		int sum=0;
		for(int i=l; i<=r ;i++){
			sum+=arr[i];
		}
		cout << sum<<"\n";
	}






}

Compilation message

trol.cpp: In function 'void pre_compute()':
trol.cpp:20:10: warning: iteration 100000 invokes undefined behavior [-Waggressive-loop-optimizations]
   20 |  }arr[i] = keepi;
      |   ~~~~~~~^~~~~~~
trol.cpp:16:16: note: within this loop
   16 |  for(int i=0; i<=maxn; i++){
      |               ~^~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1116 KB Output is correct
2 Runtime error 2 ms 1884 KB Execution killed with signal 11
3 Runtime error 3 ms 2140 KB Execution killed with signal 11
4 Runtime error 3 ms 2140 KB Execution killed with signal 11
5 Runtime error 3 ms 2140 KB Execution killed with signal 11