/ SeriousOJ /

Record Detail

Compile Error

foo.cc:93:17: error: use of 'auto' in parameter declaration only available with '-std=c++14' or '-std=gnu++14'
   93 | auto operator<<(auto &o, const auto &x) -> decltype(end(x), o) {
      |                 ^~~~
foo.cc:93:32: error: use of 'auto' in parameter declaration only available with '-std=c++14' or '-std=gnu++14'
   93 | auto operator<<(auto &o, const auto &x) -> decltype(end(x), o) {
      |                                ^~~~
foo.cc:93:56: error: no matching function for call to 'end(const int&)'
   93 | auto operator<<(auto &o, const auto &x) -> decltype(end(x), o) {
      |                                                     ~~~^~~
In file included from /usr/include/c++/13/bits/algorithmfwd.h:39,
                 from /usr/include/c++/13/bits/stl_algo.h:59,
                 from /usr/include/c++/13/algorithm:61,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:51,
                 from foo.cc:21:
/usr/include/c++/13/initializer_list:99:5: note: candidate: 'template<class _Tp> constexpr const _Tp* std::end(initializer_list<_Tp>)'
   99 |     end(initializer_list<_Tp> __ils) noexcept
      |     ^~~
/usr/include/c++/13/initializer_list:99:5: note:   template argument deduction/substitution failed:
foo.cc:93:56: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   93 | auto operator<<(auto &o, const auto &x) -> decltype(end(x), o) {
      |                                                     ~~~^~~
In file included from /usr/include/c++/13/string:53,
                 from /usr/include/c++/13/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:52:
/usr/include/c++/13/bits/range_access.h:74:5: note: candidate: 'template<class _Container> decltype (__cont.end()) std::end(_Container&)'
   74 |     end(_Container& __cont) -> decltype(__cont.end())
      |     ^~~
/usr/include/c++/13/bits/range_access.h:74:5: note:   template argument deduction/substitution failed:
/usr/include/c++/13/bits/range_access.h: In substitution of 'template<class _Container> decltype (__cont.end()) std::end(_Container&) [with _Container = const int]':
foo.cc:93:56:   required from here
/usr/include/c++/13/bits/range_access.h:74:48: error: request for member 'end' in '__cont', which is of non-class type 'const int'
   74 |     end(_Container& __cont) -> decltype(__cont.end())
      |                                         ~~~~~~~^~~
/usr/include/c++/13/bits/range_access.h:85:5: note: candidate: 'template<class _Container> decltype (__cont.end()) std::end(const _Container&)'
   85 |     end(const _Container& __cont) -> decltype(__cont.end())
      |     ^~~
/usr/include/c++/13/bits/range_access.h:85:5: note:   template argument deduction/substitution failed:
/usr/include/c++/13/bits/range_access.h: In substitution of 'template<class _Container> decltype (__cont.end()) std::end(const _Container&) [with _Container = int]':
foo.cc:93:56:   required from here
/usr/include/c++/13/bits/range_access.h:85:54: error: request for member 'end' in '__cont', which is of non-class type 'const int'
   85 |     end(const _Container& __cont) -> decltype(__cont.end())
      |                                               ~~~~~~~^~~
/usr/include/c++/13/bits/range_access.h:106:5: note: candidate: 'template<class _Tp, long unsigned int _Nm> _Tp* std::end(_Tp (&)[_Nm])'
  106 |     end(_Tp (&__arr)[_Nm]) noexcept
      |     ^~~
/usr/include/c++/13/bits/range_access.h:106:5: note:   template argument deduction/substitution failed:
foo.cc:93:56: note:   mismatched types '_Tp [_Nm]' and 'const int'
   93 | auto operator<<(auto &o, const auto &x) -> decltype(end(x), o) {
      |                                                     ~~~^~~
In file included from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:166:
/usr/include/c++/13/valarray:1249:5: note: candidate: 'template<class _Tp> _Tp* std::end(valarray<_Tp>&)'
 1249 |     end(valarray<_Tp>& __va) noexcept
      |     ^~~
/usr/include/c++/13/valarray:1249:5: note:   template argument deduction/substitution failed:
foo.cc:93:56: note:   mismatched types 'std::valarray<_Tp>' and 'const int'
   93 | auto operator<<(auto &o, const auto &x) -> decltype(end(x), o) {
      |                                                     ~~~^~~
/usr/include/c++/13/valarray:1265:5: note: candidate: 'template<class _Tp> const _Tp* std::end(const valarray<_Tp>&)'
 1265 |     end(const valarray<_Tp>& __va) noexcept
      |     ^~~
/usr/include/c++/13/valarray:1265:5: note:   template argument deduction/substitution failed:
foo.cc:93:56: note:   mismatched types 'const std::valarray<_Tp>' and 'const int'
   93 | auto operator<<(auto &o, const auto &x) -> decltype(end(x), o) {
      |                                                     ~~~^~~
foo.cc:93:56: error: no matching function for call to 'end(const int&)'
/usr/include/c++/13/initializer_list:99:5: note: candidate: 'template<class _Tp> constexpr const _Tp* std::end(initializer_list<_Tp>)'
   99 |     end(initializer_list<_Tp> __ils) noexcept
      |     ^~~
/usr/include/c++/13/initializer_list:99:5: note:   templa

Code

//████████╗██╗███╗░░██╗  ██╗░░░░░███████╗
//╚══██╔══╝██║████╗░██║  ██║░░░░░██╔════╝
//░░░██║░░░██║██╔██╗██║  ██║░░░░░█████╗░░
//░░░██║░░░██║██║╚████║  ██║░░░░░██╔══╝░░
//░░░██║░░░██║██║░╚███║  ███████╗███████╗
//░░░╚═╝░░░╚═╝╚═╝░░╚══╝  ╚══════╝╚══════╝
//   __________________
//  | ________________ |
//  ||          ____  ||
//  ||   /\    |      ||
//  ||  /__\   |      ||
//  || /    \  |____  ||
//  ||________________||
//  |__________________|
//  \###################\
//   \###################\
//    \        ____       \
//     \_______\___\_______\
// An AC a day keeps the doctor away.

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define vt vector
#define all(x) begin(x), end(x)
#define allr(x) rbegin(x), rend(x)
#define ub upper_bound
#define lb lower_bound
#define db double
#define ld long db
#define ll int64_t
#define vll vt<ll>  
#define vvll vt<vll>
#define pll pair<ll, ll>    
#define vpll vt<pll>
#define vc vt<char> 
#define vvc vt<vc>
#define vi vt<int>
#define vvi vt<vi>
#define vvvi vt<vvi>
#define pii pair<int, int>
#define vpii vt<pii>
#define vs vt<string>
#define vvs vt<vs>
#define vb vt<bool>
#define vvb vt<vb>
#define vvpii vt<vpii>
#define vd vt<db>
#define ar(x) array<int, x>
#define var(x) vt<ar(x)>
#define pq priority_queue
#define mset(m, v) memset(m, v, sizeof(m))
#define pb push_back
#define ff first
#define ss second
#define sv string_view
#define MP make_pair
#define MT make_tuple
#define rsz resize
#define sum(x) accumulate(all(x), 0LL)
#define srt(x) sort(all(x))
#define srtR(x) sort(allr(x))
#define srtU(x) sort(all(x)), (x).erase(unique(all(x)), (x).end())
#define SORTED(x) is_sorted(all(x))
#define rev(x) reverse(all(x))
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) (a * b) / gcd(a, b)
#define MAX(a) *max_element(all(a)) 
#define MIN(a) *min_element(all(a))

//SGT DEFINE
#define lc i * 2 + 1
#define rc i * 2 + 2
#define lp lc, left, middle
#define rp rc, middle + 1, right
#define entireTree 0, 0, n - 1
#define midPoint left + (right - left) / 2
#define pushDown push(i, left, right)
#define iterator int i, int left, int right

#define IOS ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

struct custom {
    static const uint64_t C = 0x9e3779b97f4a7c15; const uint32_t RANDOM = std::chrono::steady_clock::now().time_since_epoch().count();
    size_t operator()(uint64_t x) const { return __builtin_bswap64((x ^ RANDOM) * C); }
    size_t operator()(const std::string& s) const { size_t hash = std::hash<std::string>{}(s); return hash ^ RANDOM; } };
template <class K, class V> using umap = std::unordered_map<K, V, custom>; template <class K> using uset = std::unordered_set<K, custom>;
    
template<typename T1, typename T2>
std::ostream& operator<<(std::ostream& o, const std::pair<T1, T2>& p) { return o << "{" << p.ff << " , " << p.ss << "}"; }
auto operator<<(auto &o, const auto &x) -> decltype(end(x), o) {
    o << "{"; int i = 0; for (const auto &e : x) { if (i++) o << " , "; o << e; } return o << "}";
}
    
template <typename T1, typename T2>  istream &operator>>(istream& in, pair<T1, T2>& input) {    return in >> input.ff >> input.ss; }
    
template <typename T> istream &operator>>(istream &in, vector<T> &v) { for (auto &el : v) in >> el; return in; }
    
template<typename K, typename V>
auto operator<<(std::ostream &o, const std::map<K, V> &m) -> std::ostream& {
    o << "{"; int i = 0;
    for (const auto &[key, value] : m) { if (i++) o << " , "; o << key << " : " << value; }
    return o << "}";
}
    
template<typename T> vt<T> uniqued(vt<T> arr) {  srtU(arr); return arr; }

#ifdef LOCAL
#define debug(x...) debug_out(#x, x)
void debug_out(const char* names) { std::cerr << std::endl; }
template <typename T, typename... Args>
void debug_out(const char* names, T value, Args... args) {
    const char* comma = strchr(names, ',');
    std::cerr << "[" << (comma ? std::string(names, comma) : names) << " = " << value << "]";
    if (sizeof...(args)) { std::cerr << ", "; debug_out(comma + 1, args...); }   
    else { std::cerr << std::endl; }
}
#define startClock clock_t tStart = clock();
#define endClock std::cout << std::fixed << std::setprecision(10) << "\nTime Taken: " << (double)(clock() - tStart) / CLOCKS_PER_SEC << " seconds" << std::endl;
#else
#define debug(...)
#define startClock
#define endClock

#endif
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define eps 1e-9
#define M_PI 3.14159265358979323846
const static ll INF = 1LL << 60;
const static int inf = 1e9 + 33;
const static int MK = 20;
const static int MX = 2e6 + 5;
const static int MOD = 1e9 + 7;
int pct(int x) { return __builtin_popcountll(x); }
const vvi dirs = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}, {1, 1}, {-1, -1}, {1, -1}, {-1, 1}}; // UP, DOWN, LEFT, RIGHT
int modExpo(ll base, ll exp, ll mod) { ll res = 1; base %= mod; while(exp) { if(exp & 1) res = (res * base) % mod; base = (base * base) % mod; exp >>= 1; } return res; }

void solve() {
    int n, m; cin >> n >> m;    
    vi a(n * m); cin >> a;
    srt(a); 
    vvi grid(n, vi(m, inf));    
    int s = 0, e = n * m - 1;
    for(int i = 0; i < n; i++) {    
        for(int j = i & 1; j < m; j += 2) { 
            grid[i][j] = a[s++];
            if(j + 1 < m && grid[i][j + 1] == inf) grid[i][j + 1] = a[e--]; 
            if(i + 1 < n && grid[i + 1][j] == inf) grid[i + 1][j] = a[e--];
        }
    }
    auto f = [&](int r, int c) -> int { 
        int mn = inf;   
        for(int i = 0; i < 4; i++) {  
            int row = r + dirs[i][0], col = c + dirs[i][1]; 
            if(row >= 0 && col >= 0 && row < n && col < m) {    
                mn = min(mn, grid[r][c] + grid[row][col]);
            }
        }
        return mn;
    };
    int ans = inf;  
    for(int i = 0; i < n; i++) {    
        for(int j = 0; j < m; j++) {    
            ans = min(ans, f(i, j));
        }
    }
    cout << ans << endl;
}

signed main() {
    IOS;
    startClock
    //generatePrime();

    int t = 1;
    cin >> t;
    for(int i = 1; i <= t; i++) {   
        //cout << "Case #" << i << ": ";  
        solve();
    }

    //endClock
    return 0;
}

//███████████████████████████████████████████████████████████████████████████████████████████████████████
//█░░░░░░░░░░░░░░█░░░░░░██████████░░░░░░█░░░░░░░░░░░░███░░░░░░░░░░█░░░░░░██████████░░░░░░█░░░░░░░░░░░░░░█
//█░░▄▀▄▀▄▀▄▀▄▀░░█░░▄▀░░░░░░░░░░██░░▄▀░░█░░▄▀▄▀▄▀▄▀░░░░█░░▄▀▄▀▄▀░░█░░▄▀░░░░░░░░░░██░░▄▀░░█░░▄▀▄▀▄▀▄▀▄▀░░█
//█░░▄▀░░░░░░░░░░█░░▄▀▄▀▄▀▄▀▄▀░░██░░▄▀░░█░░▄▀░░░░▄▀▄▀░░█░░░░▄▀░░░░█░░▄▀▄▀▄▀▄▀▄▀░░██░░▄▀░░█░░▄▀░░░░░░░░░░█
//█░░▄▀░░█████████░░▄▀░░░░░░▄▀░░██░░▄▀░░█░░▄▀░░██░░▄▀░░███░░▄▀░░███░░▄▀░░░░░░▄▀░░██░░▄▀░░█░░▄▀░░█████████
//█░░▄▀░░░░░░░░░░█░░▄▀░░██░░▄▀░░██░░▄▀░░█░░▄▀░░██░░▄▀░░███░░▄▀░░███░░▄▀░░██░░▄▀░░██░░▄▀░░█░░▄▀░░█████████
//█░░▄▀▄▀▄▀▄▀▄▀░░█░░▄▀░░██░░▄▀░░██░░▄▀░░█░░▄▀░░██░░▄▀░░███░░▄▀░░███░░▄▀░░██░░▄▀░░██░░▄▀░░█░░▄▀░░██░░░░░░█
//█░░▄▀░░░░░░░░░░█░░▄▀░░██░░▄▀░░██░░▄▀░░█░░▄▀░░██░░▄▀░░███░░▄▀░░███░░▄▀░░██░░▄▀░░██░░▄▀░░█░░▄▀░░██░░▄▀░░█
//█░░▄▀░░█████████░░▄▀░░██░░▄▀░░░░░░▄▀░░█░░▄▀░░██░░▄▀░░███░░▄▀░░███░░▄▀░░██░░▄▀░░░░░░▄▀░░█░░▄▀░░██░░▄▀░░█
//█░░▄▀░░░░░░░░░░█░░▄▀░░██░░▄▀▄▀▄▀▄▀▄▀░░█░░▄▀░░░░▄▀▄▀░░█░░░░▄▀░░░░█░░▄▀░░██░░▄▀▄▀▄▀▄▀▄▀░░█░░▄▀░░░░░░▄▀░░█
//█░░▄▀▄▀▄▀▄▀▄▀░░█░░▄▀░░██░░░░░░░░░░▄▀░░█░░▄▀▄▀▄▀▄▀░░░░█░░▄▀▄▀▄▀░░█░░▄▀░░██░░░░░░░░░░▄▀░░█░░▄▀▄▀▄▀▄▀▄▀░░█
//█░░░░░░░░░░░░░░█░░░░░░██████████░░░░░░█░░░░░░░░░░░░███░░░░░░░░░░█░░░░░░██████████░░░░░░█░░░░░░░░░░░░░░█
//███████████████████████████████████████████████████████████████████████████████████████████████████████

Information

Submit By
Type
Submission
Problem
P1065 Matrix Sum
Language
C++11 (G++ 13.2.0)
Submit At
2024-10-05 16:42:45
Judged At
2024-11-11 02:40:14
Judged By
Score
0
Total Time
0ms
Peak Memory
0 Bytes