Submission #205407

# Submission time Handle Problem Language Result Execution time Memory
205407 2020-02-28T20:27:49 Z luciocf Trol (COCI19_trol) C++14
50 / 50
5 ms 376 KB
#include <bits/stdc++.h>

typedef long long ll;

using namespace std;

int main(void)
{
	int q;
	scanf("%d", &q);

	while(q--)
	{
		long long l, r;

		scanf("%lld %lld", &l, &r);

		if (r-l+1 <= 9)
		{
			int ans = 0;
			for (ll i = l; i <= r; i++)
			{
				ll x = i%9;
				if (x == 0) x = 9;

				ans += x;
			}

			printf("%d\n", ans);
		}
		else
		{
			ll ans = 0;

			ll a;
			for (ll i = l; i <= r; i++)
			{
				ll x = i%9;
				if (x == 0) x = 9;

				ans += 1ll*x;
				if (x == 9)
				{
					a = i+1;
					break;
				}
			}

			ll b;
			for (ll i = r; i >= l; i--)
			{
				ll x = i%9;
				if (x == 0) x = 9;

				ans += x;
				if (x == 1)
				{
					b = i-1;
					break;
				}
			}

			ans += 45ll*((b-a+1)/9);

			printf("%lld\n", ans);
		}
	}
}

Compilation message

trol.cpp: In function 'int main()':
trol.cpp:10:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &q);
  ~~~~~^~~~~~~~~~
trol.cpp:16:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld %lld", &l, &r);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~
trol.cpp:63:19: warning: 'b' may be used uninitialized in this function [-Wmaybe-uninitialized]
    ans += 45ll*((b-a+1)/9);
                  ~^~
trol.cpp:63:19: warning: 'a' 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 5 ms 256 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 256 KB Output is correct