# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
485653 | tato | Trol (COCI19_trol) | C++14 | 1 ms | 204 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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);
}
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;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |