답안 #485655

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
485655 2021-11-08T20:27:01 Z tato Trol (COCI19_trol) C++
10 / 50
1 ms 204 KB
#include <bits/stdc++.h>
#define ll long long 
#define pb push_back
using namespace std;

ll a[31],b[31];
ll cnt[31];

void answer(ll l,ll r)
{
	vector<int> v1,v2,v3,v4;
	
	
	
	ll n=l,m=r;
	
	while(n>0)
		{
			v1.pb(n%10);
			n/=10;
		}
	while(m>0)
	{
		v2.pb(m%10);
		m/=10;
	}
	n=l; m=r;
	

	ll pas1=0,pas2=0;
	
	for(int i=0; i<v1.size(); i++)
		pas1=pas1+v1[i]+v1[i]*a[i]+b[v1[i]-1]*cnt[i];
	
	for(int i=0; i<v2.size(); i++)
		pas2=pas2+v2[i]+v2[i]*a[i]+b[v2[i]-1]*cnt[i];
		
		for(int i=v1.size()-1; i>=0; i--)
			{
				pas1+=((n/cnt[i])*(n%cnt[i]));
				n=n%cnt[i];
			}
		for(int i=v2.size(); i>=0; i--)
			{
				pas2+=((m/cnt[i])*(m%cnt[i]));
				m=m%cnt[i];
			}
	cout<<abs(pas1-pas2)<<endl;
}
int main()
{
	a[0]=0;a[1]=45;  b[0]=0; cnt[0]=1; b[1]=1; 
	for(int i=2; i<=30; i++)
	{
		cnt[i-1]=10*cnt[i-2];
		a[i]=a[i-1]*10+45*cnt[i-1];
		b[i]=b[i-1]+i;
	}
	
int t;
cin>>t;

	while(t--)
	{
		ll l,r;
		cin>>l>>r;
		answer(l-1,r);
	}
		
		
	
	
	
	return 0;
}

Compilation message

trol.cpp: In function 'void answer(long long int, long long int)':
trol.cpp:32:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |  for(int i=0; i<v1.size(); i++)
      |               ~^~~~~~~~~~
trol.cpp:35:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |  for(int i=0; i<v2.size(); i++)
      |               ~^~~~~~~~~~
trol.cpp:35:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   35 |  for(int i=0; i<v2.size(); i++)
      |  ^~~
trol.cpp:38:3: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   38 |   for(int i=v1.size()-1; i>=0; i--)
      |   ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Incorrect 0 ms 204 KB Output isn't correct
3 Incorrect 1 ms 204 KB Output isn't correct
4 Incorrect 1 ms 204 KB Output isn't correct
5 Incorrect 1 ms 204 KB Output isn't correct