当前位置: 首页 > 工具软件 > ATC > 使用案例 >

Atc ABC234 A-E

孟树
2023-12-01

A-D水
E:暴力打表1-1e17

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mi[20];
ll dfs(ll dep,ll d,ll now)
{
    if (now > 9 || now<0)return -1;
    if (dep == 0)return now;
    ll res = dfs(dep - 1, d, now + d);
    if (res == -1)return -1;
    return res + now * mi[dep];
}
void fun(ll x, vector<ll>& v)
{
    for (ll i = 1;i <= 9;i++)for(ll k=-9;k<=9;k++)
    {
        ll res = dfs(x - 1, k, i + k);
        if (res == -1)continue;
        else v.push_back(res + i * mi[x]);
    }
}
int main()
{
    mi[0] = 1;
    for (ll i = 1;i <= 18;i++)mi[i] = mi[i - 1] * 10;
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    vector<ll> v;
    for (ll i = 1;i <= 99;i++)v.push_back(i);
    for (ll i = 2;i <= 17;i++)
    {
        fun(i, v);
    }
    sort(v.begin(), v.end());
    ll n;
    cin >> n;
    cout << *lower_bound(v.begin(), v.end(), n);
    return 0;
}

 类似资料: