Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include <cstdlib>
- #include <cstring>
- #include <cmath>
- #include <climits>
- #include <cfloat>
- #include <ctime>
- #include <cassert>
- #include <map>
- #include <utility>
- #include <set>
- #include <iostream>
- #include <memory>
- #include <string>
- #include <vector>
- #include <algorithm>
- #include <functional>
- #include <sstream>
- #include <complex>
- #include <stack>
- #include <queue>
- #include <numeric>
- #include <list>
- #include <iomanip>
- #include <fstream>
- #include <bitset>
- #include <tuple>
- #define mp make_pair
- #define mt make_tuple
- #define rep(i, n) for (int i = 0; i < (n); i++)
- using namespace std;
- typedef long long ll;
- typedef pair<int, int> pii;
- const int INF = 1 << 29;
- const double EPS = 1e-9;
- const int MOD = 100000007;
- const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
- class Coversta {
- public:
- int N, M;
- class State {
- public:
- int y, x;
- int sum;
- State(int _y, int _x, int _sum) {
- y = _y;
- x = _x;
- sum = _sum;
- }
- bool operator<(const State &rst) const { return sum < rst.sum; }
- };
- bool check(int y, int x) {//x,//y
- if (y < 0 || y >= N || x < 0 || x >= M) {
- return false;
- }
- return true;
- }
- int dp[110][110];
- int place(vector<string> a, vector<int> x, vector<int> y) {
- int result;
- swap(x, y);
- N = a.size();//y
- M = a[0].length();//x
- int L = x.size();
- memset(dp, 0, sizeof(dp));
- priority_queue<State> que;
- for (int i = 0; i < N; i++) {//y
- for (int j = 0; j < M; j++) {//x
- int tmp = 0;
- for (int k = 0; k < L; k++) {
- int ny, nx;
- ny = i + y[k];//x
- nx = j + x[k];//y
- if (check(ny, nx)) {//x,y
- tmp += (a[ny][nx] - '0');
- }
- }
- dp[i][j] = tmp;
- que.push(State(i, j, tmp));
- }
- }
- result = 0;
- for (int i = 0; i < N; i++) {
- for (int j = 0; j < M; j++) {
- int cost1 = dp[i][j];
- priority_queue<State> que1 = que;
- int cnt = 0;
- while (!que1.empty()) {
- State pos = que1.top();
- que1.pop();
- if (cost1 + pos.sum <= result) {
- break;
- }
- if (i == pos.y and j == pos.x)
- continue;
- set<pii> flag;
- for (int k = 0; k < L; k++) {
- int ny, nx;
- ny = i + y[k];
- nx = j + x[k];
- if (check(ny, nx)) {
- flag.insert(mp(ny, nx));
- }
- }
- int cost2 = dp[pos.y][pos.x];
- for (int k = 0; k < L; k++) {
- int ny, nx;
- ny = pos.y + y[k];
- nx = pos.x + x[k];
- if (check(ny, nx)) {
- if (flag.count(mp(ny, nx))) {
- cost2 -= (a[ny][nx] - '0');
- }
- }
- }
- result = max(result, cost1 + cost2);
- cnt++;
- // if (cnt >= 1000)break;
- }
- }
- }
- return result;
- }
- };
- // CUT begin
- ifstream data("Coversta.sample");
- string next_line() {
- string s;
- getline(data, s);
- return s;
- }
- template <typename T> void from_stream(T &t) {
- stringstream ss(next_line());
- ss >> t;
- }
- void from_stream(string &s) { s = next_line(); }
- template <typename T> void from_stream(vector<T> &ts) {
- int len;
- from_stream(len);
- ts.clear();
- for (int i = 0; i < len; ++i) {
- T t;
- from_stream(t);
- ts.push_back(t);
- }
- }
- template <typename T> string to_string(T t) {
- stringstream s;
- s << t;
- return s.str();
- }
- string to_string(string t) { return "\"" + t + "\""; }
- bool do_test(vector<string> a, vector<int> x, vector<int> y, int __expected) {
- time_t startClock = clock();
- Coversta *instance = new Coversta();
- int __result = instance->place(a, x, y);
- double elapsed = (double)(clock() - startClock) / CLOCKS_PER_SEC;
- delete instance;
- if (__result == __expected) {
- cout << "PASSED!"
- << " (" << elapsed << " seconds)" << endl;
- return true;
- } else {
- cout << "FAILED!"
- << " (" << elapsed << " seconds)" << endl;
- cout << " Expected: " << to_string(__expected) << endl;
- cout << " Received: " << to_string(__result) << endl;
- return false;
- }
- }
- int run_test(bool mainProcess, const set<int> &case_set, const string command) {
- int cases = 0, passed = 0;
- while (true) {
- if (next_line().find("--") != 0)
- break;
- vector<string> a;
- from_stream(a);
- vector<int> x;
- from_stream(x);
- vector<int> y;
- from_stream(y);
- next_line();
- int __answer;
- from_stream(__answer);
- cases++;
- if (case_set.size() > 0 && case_set.find(cases - 1) == case_set.end())
- continue;
- cout << " Testcase #" << cases - 1 << " ... ";
- if (do_test(a, x, y, __answer)) {
- passed++;
- }
- }
- if (mainProcess) {
- cout << endl << "Passed : " << passed << "/" << cases << " cases" << endl;
- int T = time(NULL) - 1433415613;
- double PT = T / 60.0, TT = 75.0;
- cout << "Time : " << T / 60 << " minutes " << T % 60 << " secs" << endl;
- cout << "Score : "
- << 250 * (0.3 + (0.7 * TT * TT) / (10.0 * PT * PT + TT * TT))
- << " points" << endl;
- }
- return 0;
- }
- int main(int argc, char *argv[]) {
- cout.setf(ios::fixed, ios::floatfield);
- cout.precision(2);
- set<int> cases;
- bool mainProcess = true;
- for (int i = 1; i < argc; ++i) {
- if (string(argv[i]) == "-") {
- mainProcess = false;
- } else {
- cases.insert(atoi(argv[i]));
- }
- }
- if (mainProcess) {
- cout << "Coversta (250 Points)" << endl << endl;
- }
- return run_test(mainProcess, cases, argv[0]);
- }
- // CUT end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement