Submission #485650

#TimeUsernameProblemLanguageResultExecution timeMemory
485650tatoTrol (COCI19_trol)C++17
0 / 50
1 ms332 KiB
#include <bits/stdc++.h> #define ll long long #define pb push_back using namespace std; ll a[10],b[10]; ll cnt[10]; void answer(int l,int r) { vector<ll> v1,v2,v3,v4; int 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<=10; 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--) { int l,r; cin>>l>>r; answer(l,r); } return 0; }

Compilation message (stderr)

trol.cpp: In function 'void answer(int, int)':
trol.cpp:32:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long 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<long long 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--)
      |   ^~~
trol.cpp: In function 'int main()':
trol.cpp:56:7: warning: iteration 8 invokes undefined behavior [-Waggressive-loop-optimizations]
   56 |   a[i]=a[i-1]*10+45*cnt[i-1];
      |   ~~~~^~~~~~~~~~~~~~~~~~~~~~
trol.cpp:53:16: note: within this loop
   53 |  for(int i=2; i<=10; i++)
      |               ~^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...