結果
| 問題 |
No.3110 Like CPCTF?
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-03-19 23:13:48 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 15 ms / 2,000 ms |
| コード長 | 1,510 bytes |
| コンパイル時間 | 2,951 ms |
| コンパイル使用メモリ | 282,236 KB |
| 実行使用メモリ | 7,844 KB |
| 最終ジャッジ日時 | 2025-04-18 19:30:16 |
| 合計ジャッジ時間 | 3,751 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 16 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
int main(){
// 入力の受け取り
int n;
cin >> n;
string s;
cin >> s;
int ans = 0;
// 連続でない長さ5の部分文字列を全探索する
vector<int> use_index(n, 0);
for(int i = 0; i < 5; i++) use_index[i] = 1;
sort(use_index.begin(), use_index.end());
do {
// 使うindexから部分文字列の構築
string str = "";
for(int i = 0; i < n; i++) {
if(use_index[i]) {
str += s[i];
}
}
// 部分文字列がCPCTF的であるかを判定する
bool is_cpctf = true;
if(str[0] == str[1]) is_cpctf = false;
if(str[0] != str[2]) is_cpctf = false;
if(str[0] == str[3]) is_cpctf = false;
if(str[0] == str[4]) is_cpctf = false;
if(str[1] == str[2]) is_cpctf = false;
if(str[1] == str[3]) is_cpctf = false;
if(str[1] == str[4]) is_cpctf = false;
if(str[2] == str[3]) is_cpctf = false;
if(str[2] == str[4]) is_cpctf = false;
if(str[3] == str[4]) is_cpctf = false;
// str[0] == str[2] であるのでこれらのif文はなくても良い
// if(str[1] == str[2]) is_cpctf = false;
// if(str[2] == str[3]) is_cpctf = false;
// if(str[2] == str[4]) is_cpctf = false;
if(is_cpctf) ans++;
}while(next_permutation(use_index.begin(), use_index.end()));
// 答えの出力
cout << ans << endl;
}