답안 #205405

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
205405 2020-02-28T20:24:44 Z luciocf Trol (COCI19_trol) C++14
30 / 50
5 ms 376 KB
#include <bits/stdc++.h>

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 (int i = l; i <= r; i++)
			{
				int x = i%9;
				if (x == 0) x = 9;

				ans += x;
			}

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

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

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

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

				ans += 1ll*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:8:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &q);
  ~~~~~^~~~~~~~~~
trol.cpp:14: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:61:19: warning: 'b' may be used uninitialized in this function [-Wmaybe-uninitialized]
    ans += 45ll*((b-a+1)/9);
                  ~^~
trol.cpp:61:19: warning: 'a' may be used uninitialized in this function [-Wmaybe-uninitialized]
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 248 KB Output is correct
3 Incorrect 5 ms 256 KB Output isn't correct
4 Correct 5 ms 256 KB Output is correct
5 Incorrect 5 ms 376 KB Output isn't correct