206802026-01-08 17:24:41ubormaciKazamatacpp17Elfogadva 40/4023ms3516 KiB
#include <iostream>
#include <algorithm> // for sort, mainly
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <array>
#include <string>
#include <cstdio>
#include <iterator>
#include <unordered_set>
#include <cstdint> // for int64_t, int32_t, etc
#include <queue>
#include <stack>
#include <deque>
#include <numeric> // gcd, lcm
#include <fstream>
#include <bitset> // for bitset
#include <iomanip>
#include <cassert> // for set with custom ordering
#include <type_traits> // for set with custom ordering
#include <utility> // for swap, forward, etc
using namespace std;

#pragma GCC optimize("O2")
// #pragma GCC optimize("O1","O2","O3","Ofast","unroll-loops")
// #pragma GCC target("sse","sse2","sse3","sse4.1","sse4.2","avx","avx2","fma")

template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }
void dbg_out() { cout << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cout << ' ' << H; dbg_out(T...); }
#ifdef LOCAL
#define dbg(...) cout << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif

/*

notes:

int64_t
stoi(string s) -> string to int
to_string() -> int (or else) to string

vector declaration:
vector<ll> v(n, 0)
vector<vector<ll>> v(n, vector<ll>(n, 0));

{if statement} ? {truth value} : {false value}

#ifdef LOCAL
    freopen("in.txt","r",stdin);
    freopen("out.txt","w",stdout);
#endif

std::lcm(ll a, ll b), std::gcd(int a, int b)

cout << fixed << setprecision(n);

set with custom ordering
set<ll, decltype(&cmp)> qu(cmp);

*/

typedef int64_t ll;

void solve() {

	ll n;
	cin >> n;

	vector<ll> v(n, 0);
	for(ll i = 0; i < n; i++) {
		cin >> v[i];
	}

	vector<ll> have(n+1, 0);

	ll loop = 0;

	queue<pair<ll,ll>> get;
	// key, loop in which it is achieved

	for(ll room = 0; room < n; room++) {

		have[(v[room] + loop) % n] = true;
		get.push({(v[room] + loop + 1) % n, loop+1});

		while(have[room] == false) {

			auto f = get.front();
			get.pop();

			have[f.first] = true;
			loop = max(loop, f.second);

			if(have[(f.first+1) % n] == false) {
				get.push({(f.first + 1) % n, f.second + 1});
			}
		}

	}

	cout << loop;

}

int main()
{
	std::ios_base::sync_with_stdio(false);
	//cin.tie(nullptr);
	//cout.tie(nullptr);

	solve();

	return 0;
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base40/40
1Elfogadva0/01ms316 KiB
2Elfogadva0/010ms1844 KiB
3Elfogadva2/21ms316 KiB
4Elfogadva2/21ms316 KiB
5Elfogadva2/21ms316 KiB
6Elfogadva2/21ms316 KiB
7Elfogadva2/21ms316 KiB
8Elfogadva2/21ms316 KiB
9Elfogadva2/21ms508 KiB
10Elfogadva2/21ms392 KiB
11Elfogadva2/223ms3016 KiB
12Elfogadva2/221ms3012 KiB
13Elfogadva2/221ms2768 KiB
14Elfogadva2/221ms2524 KiB
15Elfogadva2/221ms2868 KiB
16Elfogadva2/221ms3420 KiB
17Elfogadva2/221ms3380 KiB
18Elfogadva2/221ms3068 KiB
19Elfogadva2/220ms3372 KiB
20Elfogadva2/221ms2240 KiB
21Elfogadva2/221ms3516 KiB
22Elfogadva2/220ms3268 KiB