提出 #577165


ソースコード 拡げる

#include<bits/stdc++.h>
using namespace std;
#define FZ(n) memset((n),0,sizeof(n))
#define FMO(n) memset((n),-1,sizeof(n))
#define F first
#define S second
#define PB push_back
#define ALL(x) begin(x),end(x)
#define SZ(x) ((int)(x).size())
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
template<typename A, typename B>
ostream& operator <<(ostream &s, const pair<A,B> &p) {
  return s<<"("<<p.first<<","<<p.second<<")";
}
template<typename T>
ostream& operator <<(ostream &s, const vector<T> &c) {
  s<<"[ ";
  for (auto it : c) s << it << " ";
  s<<"]";
  return s;
}
// Let's Fight!

typedef long long LL;

LL N, N10;
LL ip, best, cost;
string ans;

LL calc(LL a, LL b){
	return min(abs(a-b), N10 - abs(a-b));
}

int main() {
    IOS;
	string str;
	cin >> str;
	N = str.length();
	ip = 0;
	N10 = 1;
	for (int i=0; i<N; i++) {
		ip = ip*10 + str[i]-'0';
		N10 *= 10;
	}
	best = 99999999999LL;
	cost = -1;
	for (int i=1; i<(1<<10); i++) {
		int nl, lst[10];
		nl = 0;
		for (int j=0; j<10; j++) {
			if (i & (1<<j)) lst[nl++] = j;
		}
		if (nl != N) continue;
		do {
			LL x = 0;
			string tmp = "";
			for (int j=0; j<N; j++) {
				x = x * 10 + lst[j];
				tmp += char(lst[j] + '0');
			}
			LL y = calc(x, ip);
			if (y > cost || y == cost && x < best) {
				best = x;
				cost = y;
				ans = tmp;
			}
		} while (next_permutation(lst, lst+nl));
	}
	cout << ans << endl;

    return 0;
}

提出情報

提出日時
問題 B - Change a Password
ユーザ bcw0x1bd2
言語 C++11 (GCC 4.8.1)
得点 100
コード長 1471 Byte
結果 AC
実行時間 2051 ms
メモリ 1176 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 29 ms 1076 KiB
00_test_01 AC 27 ms 1168 KiB
00_test_02 AC 39 ms 1172 KiB
00_test_03 AC 1965 ms 1072 KiB
01_rand_00 AC 823 ms 1172 KiB
01_rand_01 AC 2006 ms 1172 KiB
01_rand_02 AC 840 ms 1172 KiB
01_rand_03 AC 90 ms 1172 KiB
01_rand_04 AC 90 ms 1168 KiB
01_rand_05 AC 88 ms 1172 KiB
01_rand_06 AC 90 ms 1156 KiB
01_rand_07 AC 280 ms 1172 KiB
01_rand_08 AC 788 ms 1172 KiB
01_rand_09 AC 1934 ms 1108 KiB
01_rand_10 AC 27 ms 1068 KiB
01_rand_11 AC 27 ms 1068 KiB
01_rand_12 AC 90 ms 1176 KiB
01_rand_13 AC 1926 ms 1168 KiB
01_rand_14 AC 27 ms 1164 KiB
01_rand_15 AC 279 ms 1072 KiB
01_rand_16 AC 30 ms 1156 KiB
01_rand_17 AC 789 ms 1076 KiB
01_rand_18 AC 32 ms 1124 KiB
01_rand_19 AC 90 ms 1072 KiB
01_rand_20 AC 28 ms 1064 KiB
01_rand_21 AC 29 ms 1080 KiB
01_rand_22 AC 1974 ms 1172 KiB
01_rand_23 AC 28 ms 1072 KiB
01_rand_24 AC 28 ms 1168 KiB
01_rand_25 AC 796 ms 1172 KiB
01_rand_26 AC 2051 ms 1072 KiB
01_rand_27 AC 28 ms 1072 KiB
01_rand_28 AC 791 ms 1164 KiB
01_rand_29 AC 2016 ms 1076 KiB
01_rand_30 AC 278 ms 1076 KiB
01_rand_31 AC 1916 ms 1072 KiB
01_rand_32 AC 40 ms 1164 KiB
01_rand_33 AC 27 ms 1080 KiB
01_rand_34 AC 797 ms 1040 KiB
01_rand_35 AC 26 ms 1164 KiB
01_rand_36 AC 278 ms 1076 KiB
01_rand_37 AC 39 ms 1076 KiB
01_rand_38 AC 27 ms 1176 KiB
01_rand_39 AC 277 ms 1172 KiB
01_rand_40 AC 1941 ms 1072 KiB
01_rand_41 AC 284 ms 1076 KiB
01_rand_42 AC 26 ms 1076 KiB
01_rand_43 AC 1935 ms 1072 KiB
01_rand_44 AC 277 ms 1160 KiB
01_rand_45 AC 40 ms 1072 KiB
01_rand_46 AC 287 ms 1164 KiB
01_rand_47 AC 1903 ms 1064 KiB
01_rand_48 AC 29 ms 1068 KiB
01_rand_49 AC 38 ms 1164 KiB
99_handmake_00 AC 1962 ms 1176 KiB
99_handmake_01 AC 2020 ms 1072 KiB
99_handmake_02 AC 1951 ms 1080 KiB
99_handmake_03 AC 1959 ms 1072 KiB
99_handmake_04 AC 1958 ms 1068 KiB
99_handmake_05 AC 1954 ms 1072 KiB
99_handmake_06 AC 1985 ms 1076 KiB