結果

問題 No.1838 Modulo Straight
ユーザー kwm_tkwm_t
提出日時 2022-02-12 11:31:39
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,798 bytes
コンパイル時間 4,499 ms
コンパイル使用メモリ 260,604 KB
実行使用メモリ 33,736 KB
最終ジャッジ日時 2023-09-10 22:34:16
合計ジャッジ時間 12,304 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
11,460 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 9 ms
4,380 KB
testcase_04 AC 7 ms
4,380 KB
testcase_05 AC 4 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 3 ms
4,380 KB
testcase_08 AC 3 ms
4,380 KB
testcase_09 AC 3 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 256 ms
33,736 KB
testcase_12 AC 255 ms
33,660 KB
testcase_13 AC 256 ms
33,684 KB
testcase_14 AC 253 ms
33,712 KB
testcase_15 AC 257 ms
33,640 KB
testcase_16 AC 227 ms
22,764 KB
testcase_17 AC 223 ms
22,972 KB
testcase_18 AC 227 ms
22,728 KB
testcase_19 AC 208 ms
19,080 KB
testcase_20 AC 206 ms
19,084 KB
testcase_21 AC 211 ms
19,100 KB
testcase_22 TLE -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
//using mint = modint1000000007;
//const int mod = 1000000007;
//using mint = modint998244353;
//const int mod = 998244353;
//const int INF = 1e9;
//const long long LINF = 1e18;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i,l,r)for(int i=(l);i<(r);++i)
#define rrep(i, n) for (int i = (n-1); i >= 0; --i)
#define rrep2(i,l,r)for(int i=(r-1);i>=(l);--i)
#define all(x) (x).begin(),(x).end()
#define allR(x) (x).rbegin(),(x).rend()
#define endl "\n"
#define P pair<int,int>
template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; }
template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; }
int op(int a, int b) { return a + b; }
int e() { return 0; }
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int m, k; cin >> m >> k;
	vector<int>v(m * k);
	vector<vector<int>>pos(m);
	rep(i, m*k) {
		int a; cin >> a;
		pos[a].push_back(i);
	}
	rep(i, m) {
		rep(j, k) {
			int idx = m * j + i;
			v[idx] = pos[i][j];
		}
	}
	long long memo = 0;
	{
		segtree<int, op, e>seg(m * k);
		rep(i, v.size()) {
			memo += seg.prod(v[i], m * k);
			seg.set(v[i], 1);
		}
	}
	long long ans = memo;
	vector<int>v2(m * k);
	rep(i, k) {
		segtree<int, op, e>seg(m * k);
		rep(j, m) {
			int idx = i * m + j;
			seg.set(v[idx], 1);
		}
		rep(j, m) {
			int idx = i * m + j;
			int get = seg.prod(0, v[idx]);
			v2[idx] = get;
		}
	}
	//rep(i, v2.size())cout << v2[i] << " ";
	//cout << endl;
	rep(i, m - 1) {
		rep(j, k) {
			int idx = m * j + i;
			int x = v2[idx];
			memo -= x;
			memo += (m - 1) - x;
		}
		chmin(ans, memo);
	}
	cout << ans << endl;
	return 0;
}
0