Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
199818 wuyixiang 早凉的函数2 C++ 解答错误 40 95 MS 1880 KB 1420 2025-11-22 09:39:19

Tests(20/50):


#include <iostream> #include <algorithm> #define int long long using namespace std; int tr[5000005][10],siz[5000005],id,n,a[200005],ans,tong[100][15]; void insert(int x) { int root = 0; for(int i = 0;i < 17;i ++) { int y = x % 10; if(!tr[root][y])tr[root][y] = ++id; root = tr[root][y]; siz[root] ++; } } int juti(int root,int x) { int ans = 0; for(int i = 0;i < 16;i ++) { int ug = tr[root][9 - x % 10]; if(!ug)return ans; ans += siz[ug]; root = ug; x /= 10; } return ans; } int query(int x) { int tn = 10 - x % 10,ans = 0; for(int i = tn;i <= 9;i ++) if(tr[0][i])ans += juti(tr[0][i],x / 10); return ans; } signed main() { ios::sync_with_stdio(0); cin.tie(0),cout.tie(0); cin >> n; for(int i = 1;i <= n;i ++) { cin >> a[i]; int p = a[i],cnt = 0; while(p) { ans += p % 10 * n * 2; tong[++cnt][p % 10] ++; p /= 10; } insert(a[i]); } for(int i = 1;i <= n;i ++) { int p = a[i]; for(int j = 1;j <= 16;j ++) { for(int k = 10 - p % 10;k <= 9;k ++)ans -= tong[j][k] * 9; p /= 10; } } for(int i = 1;i <= n;i ++)ans -= query(a[i]) * 9; cout << ans; }


测评信息: