結果
| 問題 |
No.238 Mr. K's Another Gift
|
| コンテスト | |
| ユーザー |
vain0
|
| 提出日時 | 2015-07-05 22:55:07 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,420 bytes |
| コンパイル時間 | 503 ms |
| コンパイル使用メモリ | 78,956 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-07 23:34:14 |
| 合計ジャッジ時間 | 2,176 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 38 WA * 2 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:57:27: warning: overflow in conversion from ‘std::__cxx11::basic_string<char>::size_type’ {aka ‘long unsigned int’} to ‘int’ changes value from ‘18446744073709551615’ to ‘-1’ [-Woverflow]
57 | int pos = string::npos;
| ~~~~~~~~^~~~
ソースコード
#include <cassert>
#include <functional>
#include <set>
#include <ctime>
#include <cmath>
#include <climits>
#include <cstring>
#include <string>
#include <queue>
#include <map>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstdio>
#ifndef ONLINE_JUDGE //POJ
# include <complex>
# include <random>
# include <array>
# define mkt make_tuple
# define empb emplace_back
#endif
#ifdef _LOCAL
# include "for_local.h"
#endif
using namespace std;
typedef unsigned int uint; typedef long long ll; typedef unsigned long long ull;
#define repi(_I, _B, _E) for(int _I = (_B); (_I) < (_E); ++ (_I))
#define rep(_I, _N) for(int _I = 0; (_I) < (_N); ++ (_I))
#define mkp make_pair
#define all(_X) (_X).begin(), (_X).end()
string src;
bool palindromize(int i, int ri, int cntInsert, int& pos, char& ch)
{
while ( i <= ri ) {
if ( src[i] != src[ri] ) {
if ( cntInsert > 0 ) {
if ( palindromize(i, ri - 1, cntInsert - 1, pos, ch) ) { pos = i; ch = src[ri]; return true; }
if ( palindromize(i + 1, ri, cntInsert - 1, pos, ch) ) { pos = ri + 1; ch = src[i]; return true; }
}
return false;
}
++i;
--ri;
}
if ( i > ri ) { pos = i; ch = 'a'; }
return true;
}
signed main()
{
cin >> src;
int pos = string::npos;
char ch = '\0';
if ( palindromize(0, src.size() - 1, 1, pos, ch) ) {
src.insert(pos, 1, ch);
cout << src << endl;
} else {
cout << "NA" << endl;
}
return 0;
}
vain0