Submission #42228346
Source Code Expand
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#define N 210000
#define fep(i,x,y) for(int i=x;i<=y;i++)
#define feq(i,x,y) for(int i=x;i>=y;i--)
using namespace std;
typedef long long LL;
typedef vector<LL> VP;
VP f[10];
int n,nn,siz[10];
LL ans=0,a[N],ji=1;
inline LL qu(LL x){return x/ji%10;}
inline LL qu2(LL x){return x%ji;}
inline int fsiz(int l,int r){
if(l>r)return 0;
if(!l)return siz[r];
return siz[r]-siz[l-1];
}
int main(){
scanf("%d",&n);
fep(i,1,n)scanf("%lld",&a[i]);
fep(T,1,15){
fep(i,0,9)f[i].clear(),siz[i]=0;
LL cnt=0;
fep(i,1,n){
LL x=qu(a[i]);cnt+=x;
f[x].push_back(a[i]);
siz[x]++;
}
fep(i,1,9)siz[i]+=siz[i-1];
nn=0;ans+=cnt*(n+n);
fep(i,0,9){
ans-=f[i].size()*fsiz(10-i,9)*9;//进位的1算在这里
for(auto x:f[i])a[++nn]=x;
}
fep(i,0,9){
int j=9-i,r=(int)f[j].size()-1;
fep(l,0,(int)f[i].size()-1){
while(r>=0 && qu2(f[i][l])+qu2(f[j][r])>=ji)r--;
ans-=((int)f[j].size()-1-r)*9;//再进位
}
}
ji*=10;
}
printf("%lld\n",ans);
return 0;
}
Submission Info
| Submission Time |
|
| Task |
C - All Pair Digit Sums |
| User |
juruozjj |
| Language |
C++ (GCC 9.2.1) |
| Score |
500 |
| Code Size |
1103 Byte |
| Status |
AC |
| Exec Time |
169 ms |
| Memory |
8104 KiB |
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:22:7: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
22 | scanf("%d",&n);
| ~~~~~^~~~~~~~~
./Main.cpp:23:17: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
23 | fep(i,1,n)scanf("%lld",&a[i]);
| ~~~~~^~~~~~~~~~~~~~
Judge Result
| Set Name |
Sample |
All |
| Score / Max Score |
0 / 0 |
500 / 500 |
| Status |
|
|
| Set Name |
Test Cases |
| Sample |
01_sample_01.txt, 01_sample_02.txt, 01_sample_03.txt |
| All |
01_sample_01.txt, 01_sample_02.txt, 01_sample_03.txt, 02_small_01.txt, 02_small_02.txt, 02_small_03.txt, 02_small_04.txt, 02_small_05.txt, 02_small_06.txt, 02_small_07.txt, 02_small_08.txt, 02_small_09.txt, 02_small_10.txt, 03_rand_1_01.txt, 03_rand_1_02.txt, 03_rand_1_03.txt, 03_rand_1_04.txt, 03_rand_1_05.txt, 04_rand_2_01.txt, 04_rand_2_02.txt, 04_rand_2_03.txt, 04_rand_2_04.txt, 04_rand_2_05.txt, 05_small_digit_01.txt, 05_small_digit_02.txt, 06_large_digit_01.txt, 06_large_digit_02.txt |
| Case Name |
Status |
Exec Time |
Memory |
| 01_sample_01.txt |
AC |
8 ms |
3148 KiB |
| 01_sample_02.txt |
AC |
2 ms |
3188 KiB |
| 01_sample_03.txt |
AC |
2 ms |
3112 KiB |
| 02_small_01.txt |
AC |
4 ms |
3176 KiB |
| 02_small_02.txt |
AC |
3 ms |
3156 KiB |
| 02_small_03.txt |
AC |
2 ms |
3196 KiB |
| 02_small_04.txt |
AC |
3 ms |
3112 KiB |
| 02_small_05.txt |
AC |
2 ms |
3212 KiB |
| 02_small_06.txt |
AC |
2 ms |
3176 KiB |
| 02_small_07.txt |
AC |
3 ms |
3184 KiB |
| 02_small_08.txt |
AC |
2 ms |
3164 KiB |
| 02_small_09.txt |
AC |
3 ms |
3140 KiB |
| 02_small_10.txt |
AC |
2 ms |
3152 KiB |
| 03_rand_1_01.txt |
AC |
166 ms |
6364 KiB |
| 03_rand_1_02.txt |
AC |
168 ms |
6440 KiB |
| 03_rand_1_03.txt |
AC |
165 ms |
6468 KiB |
| 03_rand_1_04.txt |
AC |
169 ms |
6352 KiB |
| 03_rand_1_05.txt |
AC |
167 ms |
6224 KiB |
| 04_rand_2_01.txt |
AC |
141 ms |
8104 KiB |
| 04_rand_2_02.txt |
AC |
145 ms |
8088 KiB |
| 04_rand_2_03.txt |
AC |
141 ms |
7752 KiB |
| 04_rand_2_04.txt |
AC |
140 ms |
8100 KiB |
| 04_rand_2_05.txt |
AC |
141 ms |
8084 KiB |
| 05_small_digit_01.txt |
AC |
77 ms |
6176 KiB |
| 05_small_digit_02.txt |
AC |
77 ms |
6092 KiB |
| 06_large_digit_01.txt |
AC |
79 ms |
6164 KiB |
| 06_large_digit_02.txt |
AC |
83 ms |
6084 KiB |