結果
| 問題 |
No.1028 闇討ち
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-04-17 21:46:29 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 3,890 bytes |
| コンパイル時間 | 930 ms |
| コンパイル使用メモリ | 104,836 KB |
| 実行使用メモリ | 17,440 KB |
| 最終ジャッジ日時 | 2024-10-03 11:57:56 |
| 合計ジャッジ時間 | 5,493 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 10 TLE * 1 -- * 9 |
ソースコード
#include <iostream>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cstdio>
#include <bitset>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <functional>
#include <stack>
#include <cmath>
#include <string>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx2")
using namespace std;
#define REP(i, N) for (int i = 0; i < (int)N; i++)
#define FOR(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define INF (1 << 30)
#define LLINF (1LL << 62)
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)
constexpr int MOD = 1000000007;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
template <class T>
string to_string(T s);
template <class S, class T>
string to_string(pair<S, T> p);
string to_string(string s) { return s; }
string to_string(const char s[]) { return to_string(string(s)); }
template <class T>
string to_string(T v) {
if (v.empty()) return "{}";
string ret = "{";
for (auto x : v) ret += to_string(x) + ",";
ret.back() = '}';
return ret;
}
template <class S, class T>
string to_string(pair<S, T> p) {
return "{" + to_string(p.first) + ":" + to_string(p.second) + "}";
}
void debug() { cerr << endl; }
template <class Head, class... Tail>
void debug(Head head, Tail... tail) {
cerr << to_string(head) << " ";
debug(tail...);
}
struct IO {
#ifdef _WIN32
inline char getchar_unlocked() { return getchar(); }
inline void putchar_unlocked(char c) { putchar(c); }
#endif
string separator = " ";
template <class T>
inline void read(T& x) {
char c;
do {
c = getchar_unlocked();
} while (c != '-' && (c < '0' || '9' < c));
bool minus = 0;
if (c == '-') {
minus = 1;
c = getchar_unlocked();
}
x = 0;
while ('0' <= c && c <= '9') {
x *= 10;
x += c - '0';
c = getchar_unlocked();
}
if (minus) x = -x;
}
inline void read(string& x) {
char c;
do {
c = getchar_unlocked();
} while (c == ' ' || c == '\n');
x.clear();
do {
x += c;
c = getchar_unlocked();
} while (c != ' ' && c != '\n' && c != EOF);
}
template <class T>
inline void read(vector<T>& v) {
for (auto& x : v) read(x);
}
template <class Head, class... Tail>
inline void read(Head& head, Tail&... tail) {
read(head);
read(tail...);
}
template <class T>
inline void write(T x) {
char buf[32];
int p = 0;
if (x < 0) {
x = -x;
putchar_unlocked('-');
}
if (x == 0) putchar_unlocked('0');
while (x > 0) {
buf[p++] = (x % 10) + '0';
x /= 10;
}
while (p) {
putchar_unlocked(buf[--p]);
}
}
inline void write(string x) {
for (char c : x) putchar_unlocked(c);
}
inline void write(const char s[]) {
for (int i = 0; s[i] != 0; ++i) putchar_unlocked(s[i]);
}
template <class T>
inline void write(vector<T> v) {
for (auto itr = v.begin(); itr + 1 != v.end(); ++itr) {
write(*itr);
write(separator);
}
write(v.back());
}
template <class Head, class... Tail>
inline void write(Head head, Tail... tail) {
write(head);
write(separator);
write(tail...);
}
template <class Head, class... Tail>
inline void writeln(Head head, Tail... tail) {
write(head, tail...);
write("\n");
}
void set_separator(string s) { separator = s; }
} io;
int main() {
int N;
io.read(N);
vector<vector<int>> A(N, vector<int>(N)), ct(N, vector<int>(N));
io.read(A);
REP(i, N) REP(j, N) {
for (int k = 0; k < N; ++k)
ct[A[i][j] - 1][k] +=
j + (k < i - j ? i - j - k : (k > i + j ? k - i - j : 0));
}
ll ans = 0;
REP(i, N) {
int mn = INF;
REP(j, N) { mn = min(mn, ct[i][j]); }
ans += mn;
}
io.writeln(ans);
return 0;
}