# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
485651 | tato | Trol (COCI19_trol) | C++14 | 1 ms | 204 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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<ll> 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);
}
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,r);
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |