Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #line 2 "Straights.cpp"
- #include "bits/stdc++.h"
- using namespace std;
- #define FOR(i, a, b) for(__typeof(b) i = a; i <= b; i++)
- #define REP(i, a) for(__typeof(a) i = 0; i < a; i++)
- #define REPN(i, a) for(__typeof(a) i = 1; i <= a; i++)
- #define ITERATE(it, v) for(__typeof((v).begin()) it = (v).begin(); it != (v).end(); it++)
- #define D(x) cout << #x << " = " << (x) << endl
- #define bitcount __builtin_popcount
- #define oo (INT_MAX / 2)
- #define pb push_back
- #define mp make_pair
- #define gcd __gcd
- typedef long long LL;
- typedef pair <int, int> pii;
- class Straights {
- public:
- int howMany( vector <int> hand, int k ) {
- int ret = 0;
- for (int i = 0; i < hand.size() - k + 1; i ++) {
- int m = 1;
- for (int j = 0; j < k; j ++) {
- m = (m * hand[i + j]);
- }
- ret += m;
- }
- return ret;
- }
- };
- // BEGIN CUT HERE
- #include <cstdio>
- #include <ctime>
- #include <iostream>
- #include <string>
- #include <vector>
- namespace moj_harness {
- using std::string;
- using std::vector;
- int run_test_case(int);
- void run_test(int casenum = -1, bool quiet = false) {
- if (casenum != -1) {
- if (run_test_case(casenum) == -1 && !quiet) {
- std::cerr << "Illegal input! Test case " << casenum << " does not exist." << std::endl;
- }
- return;
- }
- int correct = 0, total = 0;
- for (int i=0;; ++i) {
- int x = run_test_case(i);
- if (x == -1) {
- if (i >= 100) break;
- continue;
- }
- correct += x;
- ++total;
- }
- if (total == 0) {
- std::cerr << "No test cases run." << std::endl;
- } else if (correct < total) {
- std::cerr << "Some cases FAILED (passed " << correct << " of " << total << ")." << std::endl;
- } else {
- std::cerr << "All " << total << " tests passed!" << std::endl;
- }
- }
- int verify_case(int casenum, const int &expected, const int &received, std::clock_t elapsed) {
- std::cerr << "Example " << casenum << "... ";
- string verdict;
- vector<string> info;
- char buf[100];
- if (elapsed > CLOCKS_PER_SEC / 200) {
- std::sprintf(buf, "time %.2fs", elapsed * (1.0/CLOCKS_PER_SEC));
- info.push_back(buf);
- }
- if (expected == received) {
- verdict = "PASSED";
- } else {
- verdict = "FAILED";
- }
- std::cerr << verdict;
- if (!info.empty()) {
- std::cerr << " (";
- for (size_t i=0; i<info.size(); ++i) {
- if (i > 0) std::cerr << ", ";
- std::cerr << info[i];
- }
- std::cerr << ")";
- }
- std::cerr << std::endl;
- if (verdict == "FAILED") {
- std::cerr << " Expected: " << expected << std::endl;
- std::cerr << " Received: " << received << std::endl;
- }
- return verdict == "PASSED";
- }
- int run_test_case(int casenum__) {
- switch (casenum__) {
- case 0: {
- int hand[] = {0,3,1,2,0,0,0,0,0,0,0,0,0};
- int k = 2;
- int expected__ = 5;
- std::clock_t start__ = std::clock();
- int received__ = Straights().howMany(vector <int>(hand, hand + (sizeof hand / sizeof hand[0])), k);
- return verify_case(casenum__, expected__, received__, clock()-start__);
- }
- case 1: {
- int hand[] = {1,1,1,1,1,1,1,1,1,1,1,1,1};
- int k = 5;
- int expected__ = 9;
- std::clock_t start__ = std::clock();
- int received__ = Straights().howMany(vector <int>(hand, hand + (sizeof hand / sizeof hand[0])), k);
- return verify_case(casenum__, expected__, received__, clock()-start__);
- }
- case 2: {
- int hand[] = {4,4,4,4,4,4,4,4,4,4,4,4,4};
- int k = 13;
- int expected__ = 67108864;
- std::clock_t start__ = std::clock();
- int received__ = Straights().howMany(vector <int>(hand, hand + (sizeof hand / sizeof hand[0])), k);
- return verify_case(casenum__, expected__, received__, clock()-start__);
- }
- case 3: {
- int hand[] = {4,0,4,0,4,0,4,0,4,0,4,0,4};
- int k = 2;
- int expected__ = 0;
- std::clock_t start__ = std::clock();
- int received__ = Straights().howMany(vector <int>(hand, hand + (sizeof hand / sizeof hand[0])), k);
- return verify_case(casenum__, expected__, received__, clock()-start__);
- }
- case 4: {
- int hand[] = {1,2,3,4,1,2,3,4,1,2,3,4,1};
- int k = 1;
- int expected__ = 31;
- std::clock_t start__ = std::clock();
- int received__ = Straights().howMany(vector <int>(hand, hand + (sizeof hand / sizeof hand[0])), k);
- return verify_case(casenum__, expected__, received__, clock()-start__);
- }
- // custom cases
- /* case 5: {
- int hand[] = ;
- int k = ;
- int expected__ = ;
- std::clock_t start__ = std::clock();
- int received__ = Straights().howMany(vector <int>(hand, hand + (sizeof hand / sizeof hand[0])), k);
- return verify_case(casenum__, expected__, received__, clock()-start__);
- }*/
- /* case 6: {
- int hand[] = ;
- int k = ;
- int expected__ = ;
- std::clock_t start__ = std::clock();
- int received__ = Straights().howMany(vector <int>(hand, hand + (sizeof hand / sizeof hand[0])), k);
- return verify_case(casenum__, expected__, received__, clock()-start__);
- }*/
- /* case 7: {
- int hand[] = ;
- int k = ;
- int expected__ = ;
- std::clock_t start__ = std::clock();
- int received__ = Straights().howMany(vector <int>(hand, hand + (sizeof hand / sizeof hand[0])), k);
- return verify_case(casenum__, expected__, received__, clock()-start__);
- }*/
- default:
- return -1;
- }
- }
- }
- #include <cstdlib>
- int main(int argc, char *argv[]) {
- if (argc == 1) {
- moj_harness::run_test();
- } else {
- for (int i=1; i<argc; ++i)
- moj_harness::run_test(std::atoi(argv[i]));
- }
- }
- // END CUT HERE
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement