提出 #577422


ソースコード 拡げる

#include<vector>
#include<iostream>
#include<map>
#include<algorithm>
#include<set>
#include<queue>
#include<cassert>
#include<cstring>
#include<cstdio>
#include<cstdlib>

using namespace std;
#define REP(i, n) for(int i=0;i<(int)(n);i++)
#define REPS(i, n) for(int i=1;i<=(int)n;i++)
#define RREP(i, n) for(int i=n-1;i>=0;i--)
#define RREPS(i, n) for(int i=n;i>0;i--)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define pb push_back
#define eb emplace_back
#define mp make_pair

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;

const int INF = 1<<29;	

int n;
ll old_, m, ans;
bool used[16];

void dfs(int depth, ll a) {
	if(depth == n) {
		if(min(abs(old_ - ans), m - abs(old_ - ans)) <  
		   min(abs(old_ - a),  m - abs(old_ - a))) {
			ans = a;
		}
		return;
	}
	for(int i = 0; i < 10; i++) {
		if(!used[i]) {
			used[i] = true;
			dfs(depth+1, a * 10 + i);
			used[i] = false;
		}
	}
}

int main() {
	string s;
	cin >> s;
	n = s.size();
	m = 1;
	REP(i, n) {
		m *= 10;
	}
	//old_ = stoi(s);
	old_ = 0;
	REP(i, n) {
		old_ = old_ * 10 + (s[i] - '0');
	}
	//cout << old_ << endl;
	ans = old_;
	dfs(0, 0);
	//string tmp = to_string((ll)ans);
	string tmp(n, '0');
	REP(i, n) {
		tmp[i] = '0' + (ans % 10);
		ans /= 10;
	}
	reverse(ALL(tmp));
	cout << tmp << endl;
	//REP(i, n-tmp.size()) cout << 0;
	//cout << ans << endl;
	return 0;
}

提出情報

提出日時
問題 B - Change a Password
ユーザ zerokugimachine
言語 C++11 (GCC 4.8.1)
得点 100
コード長 1466 Byte
結果 AC
実行時間 209 ms
メモリ 928 KiB

ジャッジ結果

セット名 All
得点 / 配点 100 / 100
結果
AC × 61
セット名 テストケース
All 00_test_00, 00_test_01, 00_test_02, 00_test_03, 01_rand_00, 01_rand_01, 01_rand_02, 01_rand_03, 01_rand_04, 01_rand_05, 01_rand_06, 01_rand_07, 01_rand_08, 01_rand_09, 01_rand_10, 01_rand_11, 01_rand_12, 01_rand_13, 01_rand_14, 01_rand_15, 01_rand_16, 01_rand_17, 01_rand_18, 01_rand_19, 01_rand_20, 01_rand_21, 01_rand_22, 01_rand_23, 01_rand_24, 01_rand_25, 01_rand_26, 01_rand_27, 01_rand_28, 01_rand_29, 01_rand_30, 01_rand_31, 01_rand_32, 01_rand_33, 01_rand_34, 01_rand_35, 01_rand_36, 01_rand_37, 01_rand_38, 01_rand_39, 01_rand_40, 01_rand_41, 01_rand_42, 01_rand_43, 01_rand_44, 01_rand_45, 01_rand_46, 01_rand_47, 01_rand_48, 01_rand_49, 99_handmake_00, 99_handmake_01, 99_handmake_02, 99_handmake_03, 99_handmake_04, 99_handmake_05, 99_handmake_06
ケース名 結果 実行時間 メモリ
00_test_00 AC 23 ms 672 KiB
00_test_01 AC 24 ms 924 KiB
00_test_02 AC 25 ms 672 KiB
00_test_03 AC 130 ms 796 KiB
01_rand_00 AC 69 ms 804 KiB
01_rand_01 AC 131 ms 804 KiB
01_rand_02 AC 67 ms 800 KiB
01_rand_03 AC 27 ms 800 KiB
01_rand_04 AC 27 ms 804 KiB
01_rand_05 AC 25 ms 804 KiB
01_rand_06 AC 26 ms 672 KiB
01_rand_07 AC 37 ms 800 KiB
01_rand_08 AC 70 ms 916 KiB
01_rand_09 AC 202 ms 920 KiB
01_rand_10 AC 23 ms 800 KiB
01_rand_11 AC 25 ms 792 KiB
01_rand_12 AC 28 ms 920 KiB
01_rand_13 AC 133 ms 792 KiB
01_rand_14 AC 24 ms 796 KiB
01_rand_15 AC 38 ms 916 KiB
01_rand_16 AC 23 ms 796 KiB
01_rand_17 AC 69 ms 672 KiB
01_rand_18 AC 23 ms 928 KiB
01_rand_19 AC 27 ms 800 KiB
01_rand_20 AC 23 ms 924 KiB
01_rand_21 AC 24 ms 800 KiB
01_rand_22 AC 199 ms 804 KiB
01_rand_23 AC 22 ms 804 KiB
01_rand_24 AC 23 ms 800 KiB
01_rand_25 AC 69 ms 800 KiB
01_rand_26 AC 199 ms 796 KiB
01_rand_27 AC 22 ms 920 KiB
01_rand_28 AC 68 ms 676 KiB
01_rand_29 AC 199 ms 804 KiB
01_rand_30 AC 37 ms 672 KiB
01_rand_31 AC 201 ms 800 KiB
01_rand_32 AC 24 ms 924 KiB
01_rand_33 AC 23 ms 924 KiB
01_rand_34 AC 69 ms 796 KiB
01_rand_35 AC 23 ms 800 KiB
01_rand_36 AC 37 ms 804 KiB
01_rand_37 AC 25 ms 800 KiB
01_rand_38 AC 23 ms 920 KiB
01_rand_39 AC 36 ms 776 KiB
01_rand_40 AC 202 ms 792 KiB
01_rand_41 AC 39 ms 800 KiB
01_rand_42 AC 26 ms 780 KiB
01_rand_43 AC 204 ms 732 KiB
01_rand_44 AC 38 ms 800 KiB
01_rand_45 AC 26 ms 800 KiB
01_rand_46 AC 39 ms 800 KiB
01_rand_47 AC 131 ms 800 KiB
01_rand_48 AC 24 ms 920 KiB
01_rand_49 AC 24 ms 916 KiB
99_handmake_00 AC 202 ms 916 KiB
99_handmake_01 AC 209 ms 800 KiB
99_handmake_02 AC 199 ms 920 KiB
99_handmake_03 AC 201 ms 808 KiB
99_handmake_04 AC 201 ms 736 KiB
99_handmake_05 AC 201 ms 920 KiB
99_handmake_06 AC 199 ms 916 KiB