結果

問題 No.2890 Chiffon
ユーザー anago-pieanago-pie
提出日時 2024-09-18 23:32:03
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 595 ms / 2,000 ms
コード長 3,191 bytes
コンパイル時間 2,619 ms
コンパイル使用メモリ 222,856 KB
実行使用メモリ 102,804 KB
最終ジャッジ日時 2024-09-18 23:32:15
合計ジャッジ時間 10,015 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 2 ms
6,940 KB
testcase_14 AC 2 ms
6,940 KB
testcase_15 AC 2 ms
6,944 KB
testcase_16 AC 2 ms
6,940 KB
testcase_17 AC 2 ms
6,940 KB
testcase_18 AC 2 ms
6,944 KB
testcase_19 AC 2 ms
6,940 KB
testcase_20 AC 2 ms
6,944 KB
testcase_21 AC 2 ms
6,940 KB
testcase_22 AC 595 ms
102,804 KB
testcase_23 AC 3 ms
5,376 KB
testcase_24 AC 3 ms
5,376 KB
testcase_25 AC 3 ms
5,376 KB
testcase_26 AC 4 ms
5,376 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 3 ms
5,376 KB
testcase_29 AC 3 ms
5,376 KB
testcase_30 AC 3 ms
5,376 KB
testcase_31 AC 3 ms
5,376 KB
testcase_32 AC 4 ms
5,376 KB
testcase_33 AC 228 ms
43,008 KB
testcase_34 AC 228 ms
43,008 KB
testcase_35 AC 233 ms
43,008 KB
testcase_36 AC 230 ms
43,008 KB
testcase_37 AC 227 ms
43,008 KB
testcase_38 AC 226 ms
43,008 KB
testcase_39 AC 227 ms
42,880 KB
testcase_40 AC 228 ms
43,008 KB
testcase_41 AC 227 ms
43,008 KB
testcase_42 AC 232 ms
43,008 KB
testcase_43 AC 217 ms
43,008 KB
testcase_44 AC 220 ms
43,008 KB
testcase_45 AC 219 ms
42,880 KB
testcase_46 AC 223 ms
43,004 KB
testcase_47 AC 230 ms
43,008 KB
testcase_48 AC 219 ms
43,008 KB
testcase_49 AC 221 ms
43,008 KB
testcase_50 AC 218 ms
43,008 KB
testcase_51 AC 217 ms
43,008 KB
testcase_52 AC 218 ms
43,008 KB
testcase_53 AC 140 ms
5,376 KB
testcase_54 AC 142 ms
29,056 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define debug 0
#define YES cout << "Yes" << endl;
#define NO cout << "No" << endl;
using ll = long long;
using ld = long double;
const int mod = 998244353;
const int MOD = 1000000007;
const double pi = atan2(0, -1);
const int inf = 1 << 31-1;
const ll INF = 1LL << 63 - 1;
#include <time.h>
#include <chrono>

//vectorの中身を空白区切りで出力
template<typename T>
void printv(vector<T> v) {
	for (int i = 0; i < v.size(); i++) {
		cout << v[i];
		if (i < v.size() - 1) {
			cout << " ";
		}
	}
	cout << endl;
}

//vectorの中身を改行区切りで出力
template<typename T>
void print1(vector<T> v) {
	for (auto x : v) {
		cout << x << endl;
	}
}

//二次元配列を出力
template<typename T>
void printvv(vector<vector<T>> vv) {
	for (vector<T> v : vv) {
		printv(v);
	}
}

//vectorを降順にソート
template<typename T>
void rsort(vector<T>& v) {
	sort(v.begin(), v.end());
	reverse(v.begin(), v.end());
}

//昇順priority_queueを召喚
template<typename T>
struct rpriority_queue {
	priority_queue<T, vector<T>, greater<T>> pq;

	void push(T x) {
		pq.push(x);
	}

	void pop() {
		pq.pop();
	}

	T top() {
		return pq.top();
	}

	size_t size() {
		return pq.size();
	}

	bool empty() {
		return pq.empty();
	}
};

//mod mod下で逆元を算出する
//高速a^n計算(mod ver.)
ll power(ll a, ll n) {
	if (n == 0) {
		return 1;
	}
	else if (n % 2 == 0) {
		ll x = power(a, n / 2);
		x *= x;
		x %= mod;
		return x;
	}
	else {
		ll x = power(a, n - 1);
		x *= a;
		x %= mod;
		return x;
	}
}
//フェルマーの小定理を利用
ll modinv(ll p) {
	return power(p, mod - 2) % mod;
}

//Mexを求める
struct Mex {
	map<int, int> mp;
	set<int> s;
	Mex(int Max) {
		for (int i = 0; i <= Max; i++) {
			s.insert(i);
		}
	}

	int _mex = 0;
	void Input(int x) {
		mp[x]++;
		s.erase(x);
		if (_mex == x) {
			_mex = *begin(s);
		}
	}

	void Remove(int x) {
		if (mp[x] == 0) {
			cout << "Mex ERROR!: NO VALUE WILL BE REMOVED" << endl;
		}
		mp[x]--;
		if (mp[x] == 0) {
			s.insert(x);
			if (*begin(s) == x) {
				_mex = x;
			}
		}
	}

	int mex(){
		return _mex;
	}
};

int main() {
	int N, K;
	cin >> N >> K;
	vector<int> A(K);
	set<int> straw;
	rep(i, K) {
		cin >> A[i];
		straw.insert(A[i]);
	}

	set<vector<int>> heap;
	vector<vector<int>> memo(K);
	rep(i, K) {
		int s = A[(K+i-1)%K] + 1, e = A[i] + 1;
		int d = (2 * N + e - s) % (2 * N);
		memo[i] = { d,s,e };
		heap.insert({ d,s,e,i });
	}

	int ans = 0;
	while (1) {
		vector<int> v = *begin(heap);
		heap.erase(v);

		int index = v[3];
		int d = v[0];
		int s = v[1], e = v[2];

		ans = max(ans, d);

		if (straw.count((e + 1) % (2 * N))) {
			break;
		}

		int next_index = (index + 1) % K;
		int next_d = memo[next_index][0], next_s = memo[next_index][1], next_e = memo[next_index][2];
		heap.erase({ next_d, next_s, next_e, next_index });
		e =(e+2)%(2*N);
		next_s = (next_s + 2) % (2 * N);
		d += 2;
		next_d -= 2;

		heap.insert({ d,s,e,index });
		heap.insert({ next_d, next_s, next_e, next_index });

		memo[index] = { d,s,e };
		memo[next_index] = { next_d, next_s, next_e };
	}

	cout << ans << endl;
}
0