Submission #1515667
Source Code Expand
#include <algorithm> #include <bitset> #include <complex> #include <deque> #include <exception> #include <fstream> #include <functional> #include <iomanip> #include <ios> #include <iosfwd> #include <iostream> #include <istream> #include <iterator> #include <limits> #include <list> #include <locale> #include <map> #include <memory> #include <new> #include <numeric> #include <ostream> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdexcept> #include <streambuf> #include <string> #include <typeinfo> #include <utility> #include <valarray> #include <vector> #define REP(i, m, n) for(int i=int(m);i<int(n);i++) #define EACH(i, c) for (auto &(i): c) #define all(c) begin(c),end(c) #define EXIST(s, e) ((s).find(e)!=(s).end()) #define SORT(c) sort(begin(c),end(c)) #define pb emplace_back #define MP make_pair #define SZ(a) int((a).size()) //#define LOCAL 1 #ifdef LOCAL #define DEBUG(s) cout << (s) << endl #define dump(x) cerr << #x << " = " << (x) << endl #define BR cout << endl; #else #define DEBUG(s) do{}while(0) #define dump(x) do{}while(0) #define BR #endif //改造 typedef long long int ll; using namespace std; //ここから編集する int rev(int num) { if (num == 1) return 2; if (num == 2) return 1; return -1; } int main() { vector<bool> input;//丸ならtrue,罰ならfalse int n; cin >> n; string str; cin >> str; for (int i = 0; i < n; i++) { if (str[i] == 'o') { input.push_back(true); } else if (str[i] == 'x') { input.push_back(false); } } vector<int> suppo;//羊なら1,オオカミなら2,何もいないなら0 for (int i = 0; i < n; i++) { suppo.push_back(0); } string ans = ""; bool mujun = true; for (int a = 1; a <= 2; a++) { for (int b = 1; b <= 2; b++) { suppo[0] = a; suppo[1] = b; //動物n-1を仮定 int lastFriends = 0; if (suppo[0] == 1) {//0番目が羊 if (input[0]) {//○とおっしゃる lastFriends = suppo[1]; } else {//罰と仰る lastFriends = rev(suppo[1]); } } else if (suppo[0] == 2) { if (input[0]) {//○といってる lastFriends = rev(suppo[1]); } else {//×と言ってる lastFriends = suppo[1]; } } //再帰的に動物を仮定 for (int i = 0; i + 2 < n; i++) { if (suppo[i + 1] == 1) { if (input[i + 1]) { suppo[i + 2] = suppo[i]; } else { suppo[i + 2] = rev(suppo[i]); } } else if (suppo[i + 1] == 2) { if (input[i + 1]) { suppo[i + 2] = rev(suppo[i]); } else { suppo[i + 2] = suppo[i]; } } } //矛盾はないか? // if (lastFriends == suppo[n - 1]) { // if (!(suppo[n - 1] == 1 && suppo[n - 2] == suppo[0])) { // } else if (!(suppo[n - 1] == 2 && suppo[n - 2] != suppo[0])) { // } else { // mujun = false; // for (int i = 0; i < n; i++) { // if (suppo[i] == 1) { // ans += 'S'; // } else if (suppo[i] == 2) { // ans += 'W'; // } // } // cout << ans << endl; // return 0; // } // } if (lastFriends == suppo[n - 1] && ((suppo[n - 1] == 1 && (suppo[n - 2] == suppo[0]) == input[n - 1]) || (suppo[n - 1] == 2 && ((suppo[n - 2] == suppo[0]) != input[n - 1])))) { for (int i = 0; i < n; i++) { if (suppo[i] == 1) { ans += 'S'; } else if (suppo[i] == 2) { ans += 'W'; } } cout << ans << endl; return 0; } //初期化 for (int i = 0; i < n; i++) { suppo[i] = 0; } } // //動物n-1を仮定 // int lastFriends = 0; // if (suppo[0] == 1) {//0番目が羊 // if (input[0]) {//○とおっしゃる // lastFriends = suppo[1]; // } else {//罰と仰る // lastFriends = rev(suppo[1]); // } // } else if (suppo[0] == 2) { // if (input[0]) {//○といってる // lastFriends = rev(suppo[1]); // } else {//×と言ってる // lastFriends = suppo[1]; // } // } // //再帰的に動物を仮定 // for (int i = 0; i + 2 < n; i++) { // if (suppo[i + 1] == 1) { // if (input[i + 1]) { // suppo[i + 2] = suppo[i]; // } else { // suppo[i + 2] = rev(suppo[i]); // } // } else if (suppo[i + 1] == 2) { // if (input[i + 1]) { // suppo[i + 2] = rev(suppo[i]); // } else { // suppo[i + 2] = suppo[i]; // } // } // } // //矛盾はないか? // if (lastFriends == suppo[n - 1]) { // mujun = false; // for (int i = 0; i < n; i++) { // if (suppo[i] == 1) { // ans += 'S'; // } else if (suppo[i] == 2) { // ans += 'W'; // } // } // cout << ans << endl; // return 0; // } // // // //初期化 // for (int i = 0; i < n; i++) { // suppo[i] = 0; // } } cout << -1 << endl; return 0; }
Submission Info
Submission Time | |
---|---|
Task | D - Menagerie |
User | homesentinel |
Language | C++14 (GCC 5.4.1) |
Score | 500 |
Code Size | 6355 Byte |
Status | AC |
Exec Time | 10 ms |
Memory | 1144 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 500 / 500 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | 00_example_01.txt, 00_example_02.txt, 00_example_03.txt |
All | 00_example_01.txt, 00_example_02.txt, 00_example_03.txt, 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 |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
00_example_01.txt | AC | 1 ms | 256 KB |
00_example_02.txt | AC | 1 ms | 256 KB |
00_example_03.txt | AC | 1 ms | 256 KB |
01.txt | AC | 6 ms | 768 KB |
02.txt | AC | 4 ms | 768 KB |
03.txt | AC | 1 ms | 256 KB |
04.txt | AC | 1 ms | 256 KB |
05.txt | AC | 8 ms | 1020 KB |
06.txt | AC | 7 ms | 1020 KB |
07.txt | AC | 2 ms | 384 KB |
08.txt | AC | 2 ms | 512 KB |
09.txt | AC | 1 ms | 256 KB |
10.txt | AC | 3 ms | 512 KB |
11.txt | AC | 9 ms | 1144 KB |
12.txt | AC | 10 ms | 1144 KB |
13.txt | AC | 9 ms | 1144 KB |