提出 #236295


ソースコード 拡げる

#include <iostream>
#include <stdio.h>
#include <istream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <complex>
#include <iomanip>


using namespace std;

typedef long long int ll;
typedef unsigned long long ull;
typedef pair<int,int> pi;
typedef pair<long, long> pl;
typedef pair<double, double> pd;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<pd> vpd;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vii;
typedef vector<vl> vll;
typedef vector<double> vec;
typedef vector<vec> mat;
typedef map<int, int> mii;
void dumppi(const pi &p) {  cout << p.first  << ' ' << p.second << endl; }
typedef pair<long, long> pl;
void dumppl(const pl &p) { cout << p.first << ' ' << p.second << endl; }
typedef vector<pi> vpi;
void dumpvpi(const vpi &vec) { for (auto v : vec) { cout << '(' << v.first << ',' << v.second << ')' << ' '; } cout << endl; }
typedef vector<bool> vb;
void dumpvb(const vb &vec) { for (auto b : vec) { cout << b << ' '; } cout << endl; }
typedef vector<int> vi;
void dumpvi(const vi &vec) { for (auto i : vec) { cout << i << ' '; } cout << endl; }
typedef vector<pl> vpl;
void dumpvpi(const vpl &vec) { for (auto v : vec) { cout << '(' << v.first << ',' << v.second << ')' << ' '; } cout << endl; }
typedef vector<vi> vii;
void dumpvii(const vii &mat) {for (auto vec : mat) {for (auto v : vec){cout << v << ' ';} cout << endl;}}


// util macro
// ----------------------------------------
#define mp make_pair
#define pb push_back
//-----------------------------------------

// iterator
// ----------------------------------------
#define all(x) (x).begin(), (x).end()
// ----------------------------------------

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
//------------------------------------------

const int INF = 1e9;
const double EPS = 1e-10;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = { 0,-1, 0, 1};

const int mod = 1000000007;
const double g = 9.8;

// POINTS
//-------------------------------------------
typedef complex<double> point;
// X : real();
// Y : imag();
double dot(point a, point b){  // inner product
    return (a * conj(b)).real();
}
double cross(point a, point b){ // outer product
    return (a * conj(b)).imag();
}
double dist(point a, point b) {
    return dot(a-b, a-b);
}
typedef vector<point> vpoint;
//-------------------------------------------

// math
//-------------------------------------------
int gcd(int a, int b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}
ll extgcd(ll a, ll b, ll& x, ll& y) {
    ll d = a;
    if (b != 0) {
        d = extgcd(b, a % b, y, x);
        y -= (a / b) * x;
    } else {
        x = 1; y = 0;
    }
    return d;
}
ll mod_pow(ll x, ll n) {
    if (n==0) return 1;
    ll res = mod_pow(x * x % mod, n / 2);
    if (n & 1) res = res * x % mod;
    return res;
}
ll m_fact(ll n) {
    ll res = 1; for (int i = 2; i <= n; i++) { res = res * i % mod; } return res;
}
ll mod_inverse(ll a) {
    ll x, y;
    extgcd(a, mod, x, y);
    return (mod + x % mod) % mod;
}
ll mod_fact(ll n, ll &e) {
    e = 0;
    if (n == 0) return 1;
    ll res = mod_fact(n / mod, e);
    e += n / mod;
    if (n / mod % 2 != 0) return res * (mod - m_fact(n % mod)) % mod;
    return res * m_fact(n % mod) % mod;
}

ll mod_comb(int n, int k) {
    if (n < 0 || k < 0 || n < k) return 0;
    ll e1, e2, e3;
    ll a1 = mod_fact(n, e1), a2 = mod_fact(k, e2), a3 = mod_fact(n-k, e3);
    if (e1 + e2 > e3) return 0;
    return a1 * mod_inverse(a2 * a3 % mod);
}
//-------------------------------------------


//-------------------------------------------
// Union Find
class uf {
private:
    vl _par = vl(0);
    vl _rank = vl(0);
public:
    uf(const ll n) {
        _par = vl(n); _rank = vl(n);
        for (ll i = 0; i < n; i++) {
            _par.at(i) = i;
            _rank.at(i) = 0;
        }
    }
    
    ll find(ll x) {
        if (_par.at(x) == x) { return x; }
        else { return _par.at(x) = find(_par.at(x)); }
    }
    
    void unite(ll x, ll y) {
        x = find(x); y = find(y);
        if (x == y) return;
        if (_rank.at(x) < _rank.at(y)) { _par.at(x) = y; }
        else { _par.at(y) = x; if (_rank.at(x) == _rank.at(y)) { _rank.at(x)++; } }
    }
    bool same(ll x, ll y) { return find(x) == find(y); }
};

//-------------------------------------------


#define  debu 0

int main(int argc, const char * argv[])
{
    ios::sync_with_stdio(false);
    
    ll A, K;
    cin >> A >> K;
    
    if ( A > 100000 ) {
        cout << -1 << endl;
        return 0;
    }
    
    ll ans = A;
    
    for (int i = 0; i <= 299999; i++) {
        stringstream ss;
        ss << i;
        string s = ss.str();
        set<char> chars;
        rep(l, s.size()) {
            chars.insert(s[l]);
        }
        if (chars.size() <= K) {
            ans = min(abs(A-i), ans);
        }
    }
    
    cout << ans << endl;
    
}

提出情報

提出日時
問題 D - 壊れた電卓
ユーザ nida_001
言語 C++11 (GCC 4.8.1)
得点 30
コード長 5342 Byte
結果 WA
実行時間 570 ms
メモリ 932 KiB

ジャッジ結果

セット名 sub All
得点 / 配点 30 / 30 0 / 70
結果
AC × 32
AC × 33
WA × 20
セット名 テストケース
sub test_01A.txt, test_02A.txt, test_04A.txt, test_05A.txt, test_07A.txt, test_09A.txt, test_10A.txt, test_11A.txt, test_12A.txt, test_13A.txt, test_15A.txt, test_17A.txt, test_18A.txt, test_19A.txt, test_21A.txt, test_22A.txt, test_23A.txt, test_25A.txt, test_27A.txt, test_28A.txt, test_29A.txt, test_31A.txt, test_33A.txt, test_34A.txt, test_35A.txt, test_37A.txt, test_38A.txt, test_40A.txt, test_42A.txt, test_44A.txt, test_46A.txt, test_48A.txt
All test_01A.txt, test_02A.txt, test_03.txt, test_04A.txt, test_05A.txt, test_06.txt, test_07A.txt, test_08.txt, test_09A.txt, test_10A.txt, test_11A.txt, test_12A.txt, test_13A.txt, test_14.txt, test_15A.txt, test_16.txt, test_17A.txt, test_18A.txt, test_19A.txt, test_20.txt, test_21A.txt, test_22A.txt, test_23A.txt, test_24.txt, test_25A.txt, test_26.txt, test_27A.txt, test_28A.txt, test_29A.txt, test_30.txt, test_31A.txt, test_32.txt, test_33A.txt, test_34A.txt, test_35A.txt, test_36.txt, test_37A.txt, test_38A.txt, test_39.txt, test_40A.txt, test_41.txt, test_42A.txt, test_43.txt, test_44A.txt, test_45.txt, test_46A.txt, test_47.txt, test_48A.txt, test_49.txt, sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt
ケース名 結果 実行時間 メモリ
sample_01.txt AC 488 ms 800 KiB
sample_02.txt WA 23 ms 804 KiB
sample_03.txt WA 23 ms 928 KiB
sample_04.txt WA 25 ms 924 KiB
test_01A.txt AC 570 ms 932 KiB
test_02A.txt AC 469 ms 928 KiB
test_03.txt WA 25 ms 928 KiB
test_04A.txt AC 461 ms 808 KiB
test_05A.txt AC 502 ms 924 KiB
test_06.txt WA 23 ms 924 KiB
test_07A.txt AC 457 ms 932 KiB
test_08.txt WA 23 ms 796 KiB
test_09A.txt AC 472 ms 928 KiB
test_10A.txt AC 469 ms 924 KiB
test_11A.txt AC 454 ms 928 KiB
test_12A.txt AC 506 ms 928 KiB
test_13A.txt AC 495 ms 924 KiB
test_14.txt WA 25 ms 924 KiB
test_15A.txt AC 504 ms 920 KiB
test_16.txt WA 25 ms 932 KiB
test_17A.txt AC 493 ms 916 KiB
test_18A.txt AC 470 ms 928 KiB
test_19A.txt AC 460 ms 800 KiB
test_20.txt WA 25 ms 924 KiB
test_21A.txt AC 458 ms 932 KiB
test_22A.txt AC 488 ms 932 KiB
test_23A.txt AC 464 ms 924 KiB
test_24.txt WA 25 ms 928 KiB
test_25A.txt AC 469 ms 844 KiB
test_26.txt WA 25 ms 800 KiB
test_27A.txt AC 464 ms 800 KiB
test_28A.txt AC 487 ms 924 KiB
test_29A.txt AC 500 ms 924 KiB
test_30.txt WA 25 ms 928 KiB
test_31A.txt AC 486 ms 792 KiB
test_32.txt WA 25 ms 800 KiB
test_33A.txt AC 490 ms 800 KiB
test_34A.txt AC 472 ms 728 KiB
test_35A.txt AC 459 ms 924 KiB
test_36.txt WA 23 ms 924 KiB
test_37A.txt AC 458 ms 928 KiB
test_38A.txt AC 513 ms 732 KiB
test_39.txt WA 23 ms 924 KiB
test_40A.txt AC 458 ms 928 KiB
test_41.txt WA 25 ms 800 KiB
test_42A.txt AC 464 ms 808 KiB
test_43.txt WA 28 ms 924 KiB
test_44A.txt AC 501 ms 808 KiB
test_45.txt WA 26 ms 928 KiB
test_46A.txt AC 459 ms 804 KiB
test_47.txt WA 23 ms 928 KiB
test_48A.txt AC 468 ms 808 KiB
test_49.txt WA 23 ms 924 KiB