Submission #936789

# Submission time Handle Problem Language Result Execution time Memory
936789 2024-03-02T17:45:32 Z mostafa133 Trol (COCI19_trol) C++14
50 / 50
0 ms 348 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
typedef long long ll;
typedef long double ld;
using namespace std;
using namespace __gnu_pbds;
using ordered_set = tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>;
#define all(x) x.begin(), x.end()
#define fast ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
const ll mod = 1e9 + 7;
ll au(string s)
{
	vector<bool> v(10);
	for (int i = 0; i < s.size(); i++)
	{
		if (v[s[i] - '0'])
		{
			return 0;
		}
		v[s[i] - '0'] = 1;
	}
	return 1;
}
int main()
{
	fast;
	// freopen("pails.in", "r", stdin);
	// freopen("pails.out", "w", stdout);
	ll q;
	cin >> q;
	while (q--)
	{
		ll l, r;
		cin >> l >> r;
		if (r - l < 9)
		{
			ll ans = 0;
			for (ll i = l; i <= r; i++)
			{
				ans += (i % 9 == 0 ? 9 : i % 9);
				if(i == 2016)
				{
					cout << ans;
				}
			}
			cout << ans << '\n';
			continue;
		}
		ll tmpl = l, tmpr = r;
		while (tmpl % 9)
		{
			tmpl++;
		}
		while (tmpr % 9)
		{
			tmpr--;
		}
		ll ans = (tmpr - tmpl) / 9;
		ans *= (9 * 5);
		// cout << ans << ' ';
		tmpl = l % 9, tmpr = r % 9;
		for (int i = tmpl; i <= 9; i++)
		{
			ans += (i % 9 == 0 ? 9 : i % 9);
			if(tmpl == 0)
				break;
		}
		// cout << ans << ' ';
		for(int i = 1; i <= tmpr; i++)
		{
			ans += (i % 9 == 0 ? 9 : i % 9);
		}
		cout << ans << '\n';
	}
	return 0;
}

Compilation message

trol.cpp: In function 'll au(std::string)':
trol.cpp:15:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   15 |  for (int i = 0; i < s.size(); i++)
      |                  ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct