Submission #175231
Source Code Expand
#pragma warning(disable:4996) #include <iostream> #include <sstream> #include <fstream> #include <complex> #include <ctime> #include <cstdlib> #include <cstring> #include <cctype> #include <string> #include <vector> #include <queue> #include <stack> #include <map> #include <set> #include <cmath> #include <algorithm> #include <functional> #include <numeric> using namespace std; typedef vector<int> vi; typedef vector<vi> vii; typedef vector<string> vs; typedef vector<bool> vb; typedef vector<vb> vbb; typedef pair<int, int> pii; typedef long long ll; typedef unsigned long long ull; #define all(a) (a).begin(),(a).end() #define rall(a) (a).rbegin(), (a).rend() #define pb push_back #define mp make_pair #define loop(i,a,b) for(int i=(a);i<ull(b);++i) #define rep(i,n) loop(i,0,n) #define iter(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i) #define riter(i,c) for(auto i=(c).rbegin(); i!=(c).rend(); ++i) const double eps = 1e-10; const double pi = acos(-1.0); const double inf = (int)1e8; namespace std { template<typename T>ostream&operator<<(ostream&os, vector<T>const&v){ iter(it, v) os << *it << (it + 1 == v.end() ? "" : ","); return os; } template<typename T, typename U>ostream&operator<<(ostream&os, const pair<T, U>&p){ return os << "[" << p.dirst << "," << p.second << "]"; } } #define clr(a,i) memset((a), (i) ,sizeof(a)) bool diff(string const& s, string const& t){ char c1[256] = {}; char c2[256] = {}; int n = s.size(); rep(i, n){ c1[s[i]]++; c2[t[i]]++; } int res = 0; loop(c, 'a', 'z' + 1){ res += max(0, c1[c] - c2[c]); } return res; } string solve(string s, int k){ string init = s; int n = s.size(); rep(i, n){ string rest = s.substr(i); //cout << rest << endl; sort(all(rest)); rep(j, rest.size()){ int mae = s.find(rest[j], i); swap(s[i], s[mae]); int d = diff(init.substr(i + 1), s.substr(i + 1)); if (d < k){ if (s[i] != init[i]) k--; break; } else{ swap(s[i], s[mae]); } } } return s; } int main(){ int n, k; while (cin >> n >> k){ string s; cin >> s; cout << solve(s, k) << endl; } }
Submission Info
Submission Time | |
---|---|
Task | C - 辞書式順序ふたたび |
User | tubo28 |
Language | C++11 (GCC 4.8.1) |
Score | 0 |
Code Size | 2447 Byte |
Status | WA |
Exec Time | 24 ms |
Memory | 932 KB |
Judge Result
Set Name | All | ||||
---|---|---|---|---|---|
Score / Max Score | 0 / 100 | ||||
Status |
|
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, 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 | 23 ms | 764 KB |
hand_1_1.txt | AC | 22 ms | 804 KB |
hand_1_2.txt | WA | 19 ms | 928 KB |
hand_1_3.txt | WA | 21 ms | 800 KB |
hand_1_4.txt | WA | 24 ms | 928 KB |
hand_1_5.txt | WA | 21 ms | 796 KB |
hand_1_6.txt | WA | 21 ms | 924 KB |
hand_1_7.txt | AC | 21 ms | 804 KB |
hand_1_8.txt | AC | 21 ms | 924 KB |
hand_2_0.txt | AC | 21 ms | 804 KB |
hand_2_1.txt | AC | 21 ms | 804 KB |
hand_2_10.txt | AC | 21 ms | 928 KB |
hand_2_2.txt | WA | 20 ms | 928 KB |
hand_2_3.txt | WA | 20 ms | 784 KB |
hand_2_4.txt | WA | 21 ms | 800 KB |
hand_2_5.txt | WA | 20 ms | 804 KB |
hand_2_6.txt | WA | 20 ms | 804 KB |
hand_2_7.txt | WA | 20 ms | 800 KB |
hand_2_8.txt | AC | 21 ms | 740 KB |
hand_2_9.txt | AC | 21 ms | 800 KB |
hand_3_2.txt | WA | 21 ms | 804 KB |
hand_3_3.txt | WA | 20 ms | 796 KB |
hand_3_4.txt | WA | 20 ms | 912 KB |
hand_3_5.txt | WA | 21 ms | 924 KB |
hand_3_6.txt | WA | 20 ms | 924 KB |
hand_4_2.txt | WA | 21 ms | 800 KB |
hand_4_3.txt | WA | 21 ms | 924 KB |
hand_4_4.txt | WA | 21 ms | 928 KB |
hand_4_5.txt | WA | 20 ms | 928 KB |
hand_4_6.txt | WA | 21 ms | 804 KB |
random_1.txt | WA | 21 ms | 924 KB |
random_10.txt | WA | 23 ms | 676 KB |
random_11.txt | WA | 24 ms | 804 KB |
random_12.txt | WA | 22 ms | 676 KB |
random_13.txt | WA | 21 ms | 756 KB |
random_14.txt | WA | 20 ms | 808 KB |
random_15.txt | AC | 21 ms | 800 KB |
random_2.txt | WA | 21 ms | 800 KB |
random_3.txt | WA | 21 ms | 804 KB |
random_4.txt | WA | 21 ms | 920 KB |
random_5.txt | AC | 21 ms | 928 KB |
random_6.txt | WA | 20 ms | 924 KB |
random_7.txt | AC | 22 ms | 804 KB |
random_8.txt | AC | 22 ms | 804 KB |
random_9.txt | WA | 23 ms | 928 KB |
sample_1.txt | AC | 21 ms | 804 KB |
sample_2.txt | AC | 21 ms | 740 KB |
sample_3.txt | AC | 20 ms | 932 KB |
sample_4.txt | AC | 21 ms | 804 KB |
small_1.txt | AC | 20 ms | 740 KB |
small_2.txt | AC | 20 ms | 676 KB |
small_3.txt | AC | 21 ms | 704 KB |
small_4.txt | AC | 21 ms | 804 KB |
small_5.txt | AC | 20 ms | 796 KB |
small_6.txt | AC | 20 ms | 800 KB |
small_7.txt | AC | 21 ms | 796 KB |
small_8.txt | AC | 22 ms | 804 KB |
small_9.txt | AC | 21 ms | 800 KB |