Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 8f6eaef

Browse files
committed
+ Single Round Match 663
1 parent 25b05b9 commit 8f6eaef

File tree

3 files changed

+726
-0
lines changed

3 files changed

+726
-0
lines changed
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
#include<bits/stdc++.h>
2+
using namespace std;
3+
4+
typedef long long int64;
5+
#define SZ(c) ((int)(c).size())
6+
#define ALL(c) (c).begin(), (c).end()
7+
8+
map<string, bool> memo;
9+
string target;
10+
11+
bool solve(string& s) {
12+
if (s == target) return true;
13+
if (s.size() <= target.size())
14+
return false;
15+
16+
if (memo.find(s) != memo.end())
17+
return memo[s];
18+
19+
bool r = memo[s];
20+
r = false;
21+
22+
if (s[0] == 'B') {
23+
string t = string(s.begin() + 1, s.end());
24+
reverse(ALL(t));
25+
if (r = solve(t))
26+
return true;
27+
}
28+
29+
if (s[s.size() - 1] == 'A') {
30+
string t = string(s.begin(), s.end() - 1);
31+
if (r = solve(t))
32+
return true;
33+
}
34+
35+
return r;
36+
}
37+
38+
struct ABBADiv1 {
39+
string canObtain(string initial, string target) {
40+
::target = initial;
41+
memo.clear();
42+
if (solve(target))
43+
return "Possible";
44+
else
45+
return "Impossible";
46+
}
47+
};
48+
49+
// CUT begin
50+
ifstream data("ABBADiv1.sample");
51+
52+
string next_line() {
53+
string s;
54+
getline(data, s);
55+
return s;
56+
}
57+
58+
template <typename T> void from_stream(T &t) {
59+
stringstream ss(next_line());
60+
ss >> t;
61+
}
62+
63+
void from_stream(string &s) {
64+
s = next_line();
65+
}
66+
67+
template <typename T>
68+
string to_string(T t) {
69+
stringstream s;
70+
s << t;
71+
return s.str();
72+
}
73+
74+
string to_string(string t) {
75+
return "\"" + t + "\"";
76+
}
77+
78+
bool do_test(string initial, string target, string __expected) {
79+
time_t startClock = clock();
80+
ABBADiv1 *instance = new ABBADiv1();
81+
string __result = instance->canObtain(initial, target);
82+
double elapsed = (double)(clock() - startClock) / CLOCKS_PER_SEC;
83+
delete instance;
84+
85+
if (__result == __expected) {
86+
cout << "PASSED!" << " (" << elapsed << " seconds)" << endl;
87+
return true;
88+
}
89+
else {
90+
cout << "FAILED!" << " (" << elapsed << " seconds)" << endl;
91+
cout << " Expected: " << to_string(__expected) << endl;
92+
cout << " Received: " << to_string(__result) << endl;
93+
return false;
94+
}
95+
}
96+
97+
int run_test(bool mainProcess, const set<int> &case_set, const string command) {
98+
int cases = 0, passed = 0;
99+
while (true) {
100+
if (next_line().find("--") != 0)
101+
break;
102+
string initial;
103+
from_stream(initial);
104+
string target;
105+
from_stream(target);
106+
next_line();
107+
string __answer;
108+
from_stream(__answer);
109+
110+
cases++;
111+
if (case_set.size() > 0 && case_set.find(cases - 1) == case_set.end())
112+
continue;
113+
114+
cout << " Testcase #" << cases - 1 << " ... ";
115+
if ( do_test(initial, target, __answer)) {
116+
passed++;
117+
}
118+
}
119+
if (mainProcess) {
120+
cout << endl << "Passed : " << passed << "/" << cases << " cases" << endl;
121+
int T = time(NULL) - 1437663843;
122+
double PT = T / 60.0, TT = 75.0;
123+
cout << "Time : " << T / 60 << " minutes " << T % 60 << " secs" << endl;
124+
cout << "Score : " << 300 * (0.3 + (0.7 * TT * TT) / (10.0 * PT * PT + TT * TT)) << " points" << endl;
125+
}
126+
return 0;
127+
}
128+
129+
int main(int argc, char *argv[]) {
130+
cout.setf(ios::fixed, ios::floatfield);
131+
cout.precision(2);
132+
set<int> cases;
133+
bool mainProcess = true;
134+
for (int i = 1; i < argc; ++i) {
135+
if ( string(argv[i]) == "-") {
136+
mainProcess = false;
137+
} else {
138+
cases.insert(atoi(argv[i]));
139+
}
140+
}
141+
if (mainProcess) {
142+
cout << "ABBADiv1 (300 Points)" << endl << endl;
143+
}
144+
return run_test(mainProcess, cases, argv[0]);
145+
}
146+
// CUT end

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /