結果

問題 No.2094 Symmetry
ユーザー tanakamidnighttanakamidnight
提出日時 2022-10-07 22:42:31
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 74 ms / 2,000 ms
コード長 8,444 bytes
コンパイル時間 4,968 ms
コンパイル使用メモリ 226,332 KB
実行使用メモリ 9,372 KB
最終ジャッジ日時 2023-09-03 14:14:26
合計ジャッジ時間 6,730 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,384 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 74 ms
9,300 KB
testcase_10 AC 73 ms
9,280 KB
testcase_11 AC 74 ms
9,232 KB
testcase_12 AC 74 ms
9,280 KB
testcase_13 AC 61 ms
7,552 KB
testcase_14 AC 73 ms
9,224 KB
testcase_15 AC 74 ms
9,232 KB
testcase_16 AC 74 ms
9,304 KB
testcase_17 AC 61 ms
7,440 KB
testcase_18 AC 61 ms
7,444 KB
testcase_19 AC 73 ms
9,280 KB
testcase_20 AC 73 ms
9,172 KB
testcase_21 AC 74 ms
9,172 KB
testcase_22 AC 74 ms
9,240 KB
testcase_23 AC 62 ms
7,344 KB
testcase_24 AC 61 ms
7,392 KB
testcase_25 AC 74 ms
9,184 KB
testcase_26 AC 73 ms
9,244 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 46 ms
9,244 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 48 ms
9,372 KB
testcase_31 AC 46 ms
9,232 KB
testcase_32 AC 48 ms
9,188 KB
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 38 ms
9,180 KB
testcase_35 AC 33 ms
9,228 KB
testcase_36 AC 34 ms
7,388 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

//@formatter:off
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;

//@formatter:off
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
using ll = long long;
using P = pair<ll, ll>;
using VI = vector<int>;
using VVI = vector<VI>;
using VVVI = vector<VVI>;
using VVVVI = vector<VVVI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using VVVL = vector<VVL>;
using VVVVL = vector<VVVL>;
using VP = vector<P>;
using VVP = vector<vector<P>>;
using VS = vector<string>;
using VC = vector<char>;
using VVC = vector<vector<char>>;
using VD = vector<double>;
using VVD = vector<vector<double>>;
using VVVD = vector<VVD>;
using I_I = pair<int, int>;
const int INF = (int)1e9 + 10;         // int max > 2*10^9
const long long INFL = (ll)2e18 + 10;  // ll max > 9*10^18

const int JU_5 = 100000;
const int JU_6 = 1000000;
const ll JU_9 = 1000000000;
const ll JU_18 = JU_9*JU_9;


#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl

template <typename T, typename C>
pair<T,C> operator+(const pair<T,C> &a, const pair<T,C> &b) { return make_pair(a.first + b.first, a.second + b.second); }
template <typename T, typename C>
pair<T,C> operator-(const pair<T,C> &a, const pair<T,C> &b) { return make_pair(a.first - b.first, a.second - b.second); }
template <typename T, typename C>
pair<T,C> operator*(const pair<T,C> &a, const pair<T,C> &b) { return make_pair(a.first * b.first, a.second * b.second); }
template <typename T, typename C>
pair<T,C> operator/(const pair<T,C> &a, const pair<T,C> &b) { return make_pair(a.first / b.first, a.second / b.second); }


// #define MOD 1000000007
#define MOD 998244353

#define pmod(x,y) ((x%y)+y)%y

/********** libs **********/
//@formatter:off
// jhelper 用変数
ostream *__cout;
istream *__cin;

void _init_io(std::istream &cin, std::ostream &cout) {
    // 入出力高速化用
    ios::sync_with_stdio(false); cin.tie(nullptr);
    // 少数15桁まで出力
    cout << std::setprecision(15);
    // jhelper 用
    __cout = &cout; __cin = &cin;
}

//@formatter:off
/* デバッグ用 出力 */
template<typename T>
ostream &operator<<(ostream &os, const deque<T> &vec) { os << "deq["; for (auto v: vec) os << v << ","; os << "]"; return os; }

template<typename T>
ostream &operator<<(ostream &os, const set<T> &vec) { os << "{"; for (auto v: vec) os << v << ","; os << "}"; return os; }

template<typename T>
ostream &operator<<(ostream &os, const unordered_set<T> &vec) { os << "{"; for (auto v: vec) os << v << ","; os << "}"; return os; }

template<typename T>
ostream &operator<<(ostream &os, const multiset<T> &vec) { os << "{"; for (auto v: vec) os << v << ","; os << "}"; return os; }

template<typename T>
ostream &operator<<(ostream &os, const unordered_multiset<T> &vec) { os << "{"; for (auto v: vec) os << v << ","; os << "}"; return os; }

template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &pa) { os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV>
ostream &operator<<(ostream &os, const map<TK, TV> &mp) { os << "{"; for (auto v: mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }

template<typename TK, typename TV>
ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp) { os << "{"; for (auto v: mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }

// print like python
// src: https://qiita.com/Lily0727K/items/06cb1d6da8a436369eed
/////////////////////////////////////////////////////////
void print() { *__cout << endl; }
template<class Head, class... Tail>
void print(Head &&head, Tail &&... tail) { *__cout << head; if (sizeof...(tail) != 0) *__cout << " "; print(forward<Tail>(tail)...); }
template<class T>
void print(vector<T> &vec) { for (auto &a: vec) { *__cout << a; if (&a != &vec.back()) *__cout << " "; } *__cout << endl; }
template<class T>
void print(vector<vector<T>> &df) { for (auto &vec: df) { print(vec); } }

// endl なし
void Print() {}
template<class Head, class... Tail>
void Print(Head &&head, Tail &&... tail) { *__cout << head; if (sizeof...(tail) != 0) *__cout << " "; Print(forward<Tail>(tail)...); }
template<class T>
void Print(vector<T> &vec) { for (auto &a: vec) { *__cout << a; if (&a != &vec.back()) *__cout << " "; } }
//@formatter:off
/*
 * org: https://atcoder.jp/contests/abc213/submissions/24901856
 * jhelper で使用するため, 全部 cin での入力にしている. (現状のレベルでは困らないので)
 */
template<class T> void scan(T& a){ *__cin >> a; }
template<class T> void scan(vector<T>&);
template<class T, class L> void scan(pair<T, L>&);
template<class T> void scan(vector<T>& a){ for(auto&& i : a) scan(i); }
template<class T, class L> void scan(pair<T, L>& p){ scan(p.first); scan(p.second); }
template<class T, size_t size> void scan(T (&a)[size]){ for(auto&& i : a) scan(i); }
void in(){}
template <class... T> void in(T&... a){ (void)initializer_list<int>{ (scan(a), 0)... }; }

#define let_v(type,name,...) vector<type>name(__VA_ARGS__)
#define let_V(type,name,size) vector<type>name(size);in(name)
#define let_vv(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define let_VV(type,name,h,w) vector<vector<type>>name(h,vector<type>(w));in(name)
#define let_vvv(type,name,h,w,...) vector<vector<vector<type>>>name(h,vector<vector<type>>(w,vector<type>(__VA_ARGS__)))
#define let_vvvv(type,name,h,w,x,...) vector<vector<vector<vector<type>>>>name(h,vector<vector<vector<type>>>(w,vector<vector<type>>(x,vector<type>(__VA_ARGS__))))

/* string 入力を vector<char> で受け取るみたいな */
vector<char> let_CharVec() { string s; *__cin >> s; return {s.begin(), s.end()}; }

//@formatter:off
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

template <class T, class C>
bool chmax(T& a, C b) { if (a < b) { a = b; return true; } return false; }
template <class T, class C>
bool chmin(T& a, C b) { if (a > b) { a = b; return true; } return false; }

template <class T>
T sum(const vector<T>& v) { T res = 0; for (size_t i = 0; i < v.size(); ++i) res += v[i]; return res; }

template<class T>
vector<pair<T, int>> idx_pair(vector<T> &vals) { vector<pair<T, int>> ans; rep(i, vals.size()) { ans.emplace_back(vals[i], i); } return ans; }

template <class T, class C>
T min(T a, C b) { return a <= b ? a : T(b); }

template <class T, class C>
T max(T a, C b) { return a >= b ? a : T(b); }


// add other source
// #include "../library/graph/UnionFind.cpp"
// #include "../library/tree/SegmentTree.cpp"
// #include "../library/graph/template.cpp"

// utils
// #include "../library/mint.cpp"
// #include "../library/string/utils.cpp"
// #include "../library/math/utils.cpp"
/**************************/

class No2094Symmetry {
public:
void solve(std::istream &cin, std::ostream &cout) { _init_io(cin, cout); int t = 1;
//    cin >> t;
    while (t--) _solve(cin, cout); }
//@formatter:on

    void _solve(std::istream &cin, std::ostream &cout) {
        // code
        ll n, k;
        cin >> n >> k;
        let_V(string, g, n * 2);
        let_VV(ll, c, 2 * n, 2 * n);
        int bc = 0, wc = 0;
        rep(i, 2 * n) {
            rep(j, 2 * n) {
                if (g[i][j] == '#')bc++;
                else wc++;
            }
        }
        VL costs;
        rep(i, 2 * n) rep(j, 2 * n) costs.push_back(c[i][j]);
        sort(rrng(costs));

        ll ans = -INFL;
        {
            ll tot = 0;
            rep(i, bc)tot += costs[i];
            chmax(ans, tot);
        }
        if (bc%2==0) {
            ll tot = k;
            VL costs2;
            rep(i, 2 * n) {
                rep(j, n) {
                    costs2.push_back(c[i][j] + c[i][2 * n - j - 1]);
                }
            }
            sort(rrng(costs2));
            rep(i, bc / 2) {
                tot += costs2[i];
            }
            chmax(ans,tot);
        }
        print(ans);

    }

};


int main() {
	No2094Symmetry solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}
0