Submission #2857252
Source Code Expand
/*
for (int i = 0; i < N; ++i){}
// 各桁の和を計算する関数
int findSumOfDigits(int n) {
int sum = 0;
while (n > 0) { // n が 0 になるまで
sum += n % 10;
n /= 10;
}
return sum;
}
sort(a, a + N, greater<int>()); // a[0:N] を大きい順にソート
int num[110] = {0}; // バケット
for (int i = 0; i < N; ++i) {
num[d[i]]++; // d[i] が 1 個増える
}
map<string, int> mp; // 連想配列 map<キー型, 値型> オブジェクト名
for (int i = 0; i < N; ++i) {
auto itr = mp.find(s[i]); // s[i] が設定されているか?
if(itr != mp.end() ) {
mp[s[i]] += 1;
}
else {
mp[s[i]] += 1 ;
}
}
stack<int> s; //intをデータとするスタックを用意
s.push(1); //{} -> {1}
printf("%d\n", s.top()); // 3
s.pop();
queue<int> que; //intをデータとするキューを用意
que.push(1); //{} -> {1}
printf("%d\n", que.front()); // 1
que.pop();
*/
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
using namespace std;
// #define for(i,a,b) for (int i=(a);i<(b);++i)
typedef long long ll;
typedef pair<int,int> point;
#define rep(i,n) for(i,0,n)
string abc = "abcdefghijklmnopqrstuvwxyz";
int main() {
// 入力
string S;
cin >> S;
// 解法
int num[26] = {0};
for (int i = 0; i < S.size(); ++i){
for (int j = 0; j < abc.size(); ++j){
if (S.substr(i, 1)==abc.substr(j,1)) num[j] = i+1;
}
}
// for (int j = 0; j < abc.size(); ++j) cout << num[j] << " ";
// cout << endl;
if (S.size()!=26){
string add = "a";
for (int i = 0; i < 26; ++i){
if (num[i]==0){
add = abc.substr(i,1);
break;
}
}
cout << S << add << endl;
// printf("%s%s\n", S, add);
}else if (S=="zyxwvutsrqponmlkjihgfedcba"){
printf("-1\n");
}else{
int S_idx[S.size()];
for (int i = 0; i < S.size(); ++i){
for (int j = 0; j < abc.size(); ++j){
if (S.substr(i, 1)==abc.substr(j,1)) S_idx[i] = j;
}
}
int change_idx = 0;
for (int i = S.size()-1; i >= 0; --i){
if (S_idx[i-1]<S_idx[i]){
change_idx = i;
break;
}
}
// cout << " change_idx " << change_idx << endl;
int num[26] = {0};
string S_new = S.substr(0,change_idx-1);
for (int i = 0; i < change_idx; ++i){
for (int j = 0; j < abc.size(); ++j){
if (S.substr(i, 1)==abc.substr(j,1)) num[j] = i+1;
}
};
for (int j = 0; j < abc.size(); ++j){
if (S.substr(change_idx+1, 1)==abc.substr(j,1)) num[j] = change_idx+1+1;
}
for (int i = 0; i < 26; ++i){
if (num[i]==0){
S_new +=abc[i];
break;
}
}
// S_new += S.substr(change_idx,1)
cout << S_new << endl;
cout << "No" << endl;
}
}
Submission Info
Submission Time |
|
Task |
A - Diverse Word |
User |
osciiart |
Language |
C++14 (GCC 5.4.1) |
Score |
0 |
Code Size |
2891 Byte |
Status |
WA |
Exec Time |
1 ms |
Memory |
256 KB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
0 / 300 |
Status |
|
|
Set Name |
Test Cases |
Sample |
s1.txt, s2.txt, s3.txt, s4.txt |
All |
01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, s1.txt, s2.txt, s3.txt, s4.txt |
Case Name |
Status |
Exec Time |
Memory |
01.txt |
WA |
1 ms |
256 KB |
02.txt |
WA |
1 ms |
256 KB |
03.txt |
WA |
1 ms |
256 KB |
04.txt |
AC |
1 ms |
256 KB |
05.txt |
AC |
1 ms |
256 KB |
06.txt |
AC |
1 ms |
256 KB |
07.txt |
AC |
1 ms |
256 KB |
08.txt |
AC |
1 ms |
256 KB |
09.txt |
AC |
1 ms |
256 KB |
10.txt |
WA |
1 ms |
256 KB |
11.txt |
WA |
1 ms |
256 KB |
12.txt |
WA |
1 ms |
256 KB |
13.txt |
WA |
1 ms |
256 KB |
14.txt |
WA |
1 ms |
256 KB |
15.txt |
WA |
1 ms |
256 KB |
16.txt |
WA |
1 ms |
256 KB |
17.txt |
WA |
1 ms |
256 KB |
18.txt |
WA |
1 ms |
256 KB |
19.txt |
WA |
1 ms |
256 KB |
s1.txt |
AC |
1 ms |
256 KB |
s2.txt |
AC |
1 ms |
256 KB |
s3.txt |
AC |
1 ms |
256 KB |
s4.txt |
WA |
1 ms |
256 KB |