Submission #4060810


Source Code Expand

#pragma once
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <numeric>
#include <iomanip>
#define M_PI acos(-1)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1000000007;
const int MAX_V = 201;
int now = 0;
int deco[1000];

int st[30][100000];
ll dp[52][2510];
const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int B[30];
int t[100010];
struct edge {
	int t;
	ll cost;
	edge(int _t,ll _cost) : t(_t)
							, cost(_cost){
	}
};
int table[15][15];
ll h;

bool use[15];
int ct[15];
bool memo[15][15][15];
string format(int val){
	ostringstream sout;
	sout << std::setfill('0') << setw(2) << val;
	return sout.str();
}
int ng[3];
bool check(int nm) {
	if (ng[0] == nm || ng[2] == nm || ng[1] == nm) return false;
	return true;
}
int f(int v) {
	if (v % 2 == 0) {
		return v / 2;
	}else return 3 * v + 1;
}
int k[105];

void Solve() {
	int n, k;
	cin >> n >> k;

	string s;
	cin >> s;
	string s2 = s;
	string os = s;

	sort(os.begin(), os.end());
	int ch = 0;
	for (size_t i = 0; i < n; i++)
	{
		string st = s;
		char c = os[i];
		if (st[i] == c) continue;
		
		for (int j = n - 1; j >= 0; j--)
		{
			if (st[j] == c) {

				swap(st[i], st[j]);
				break;
			}
		}
		int count = 0;
		for (size_t j = 0; j < n; j++)
		{
			if (st[j] != s2[j]) count++;
		}
		if (count <= k) {
			s = st;
		}
		else break;
	}
	cout << s << endl;

}
int main() {
	Solve();
	return 0;
}

Submission Info

Submission Time
Task C - 辞書式順序ふたたび
User moxn_nxom
Language C++14 (GCC 5.4.1)
Score 0
Code Size 2235 Byte
Status WA
Exec Time 1 ms
Memory 256 KB

Compile Error

./Main.cpp:1:9: warning: #pragma once in main file
 #pragma once
         ^
./Main.cpp:19:0: warning: "M_PI" redefined
 #define M_PI acos(-1)
 ^
In file included from /usr/include/c++/5/cmath:44:0,
                 from ./Main.cpp:15:
/usr/include/math.h:372:0: note: this is the location of the previous definition
 # define M_PI  3.14159265358979323846 /* pi */
 ^

Judge Result

Set Name All
Score / Max Score 0 / 100
Status
AC × 39
WA × 19
Set Name Test Cases
All hand_1_0.txt, hand_1_1.txt, hand_1_2.txt, hand_1_3.txt, hand_1_4.txt, hand_1_5.txt, hand_1_6.txt, hand_1_7.txt, hand_1_8.txt, hand_2_0.txt, hand_2_1.txt, hand_2_10.txt, hand_2_2.txt, hand_2_3.txt, hand_2_4.txt, hand_2_5.txt, hand_2_6.txt, hand_2_7.txt, hand_2_8.txt, hand_2_9.txt, hand_3_2.txt, hand_3_3.txt, hand_3_4.txt, hand_3_5.txt, hand_3_6.txt, hand_4_2.txt, hand_4_3.txt, hand_4_4.txt, hand_4_5.txt, hand_4_6.txt, random_1.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_2.txt, random_3.txt, random_4.txt, random_5.txt, random_6.txt, random_7.txt, random_8.txt, random_9.txt, sample_1.txt, sample_2.txt, sample_3.txt, sample_4.txt, small_1.txt, small_2.txt, small_3.txt, small_4.txt, small_5.txt, small_6.txt, small_7.txt, small_8.txt, small_9.txt
Case Name Status Exec Time Memory
hand_1_0.txt AC 1 ms 256 KB
hand_1_1.txt AC 1 ms 256 KB
hand_1_2.txt AC 1 ms 256 KB
hand_1_3.txt AC 1 ms 256 KB
hand_1_4.txt AC 1 ms 256 KB
hand_1_5.txt WA 1 ms 256 KB
hand_1_6.txt AC 1 ms 256 KB
hand_1_7.txt AC 1 ms 256 KB
hand_1_8.txt AC 1 ms 256 KB
hand_2_0.txt AC 1 ms 256 KB
hand_2_1.txt AC 1 ms 256 KB
hand_2_10.txt AC 1 ms 256 KB
hand_2_2.txt AC 1 ms 256 KB
hand_2_3.txt AC 1 ms 256 KB
hand_2_4.txt AC 1 ms 256 KB
hand_2_5.txt AC 1 ms 256 KB
hand_2_6.txt AC 1 ms 256 KB
hand_2_7.txt AC 1 ms 256 KB
hand_2_8.txt AC 1 ms 256 KB
hand_2_9.txt AC 1 ms 256 KB
hand_3_2.txt AC 1 ms 256 KB
hand_3_3.txt WA 1 ms 256 KB
hand_3_4.txt WA 1 ms 256 KB
hand_3_5.txt WA 1 ms 256 KB
hand_3_6.txt AC 1 ms 256 KB
hand_4_2.txt AC 1 ms 256 KB
hand_4_3.txt WA 1 ms 256 KB
hand_4_4.txt WA 1 ms 256 KB
hand_4_5.txt WA 1 ms 256 KB
hand_4_6.txt WA 1 ms 256 KB
random_1.txt WA 1 ms 256 KB
random_10.txt WA 1 ms 256 KB
random_11.txt WA 1 ms 256 KB
random_12.txt WA 1 ms 256 KB
random_13.txt WA 1 ms 256 KB
random_14.txt WA 1 ms 256 KB
random_15.txt AC 1 ms 256 KB
random_2.txt WA 1 ms 256 KB
random_3.txt WA 1 ms 256 KB
random_4.txt WA 1 ms 256 KB
random_5.txt AC 1 ms 256 KB
random_6.txt WA 1 ms 256 KB
random_7.txt AC 1 ms 256 KB
random_8.txt AC 1 ms 256 KB
random_9.txt WA 1 ms 256 KB
sample_1.txt AC 1 ms 256 KB
sample_2.txt AC 1 ms 256 KB
sample_3.txt AC 1 ms 256 KB
sample_4.txt AC 1 ms 256 KB
small_1.txt AC 1 ms 256 KB
small_2.txt AC 1 ms 256 KB
small_3.txt AC 1 ms 256 KB
small_4.txt AC 1 ms 256 KB
small_5.txt AC 1 ms 256 KB
small_6.txt AC 1 ms 256 KB
small_7.txt AC 1 ms 256 KB
small_8.txt AC 1 ms 256 KB
small_9.txt AC 1 ms 256 KB