22792023-01-09 12:05:31rennKazamatacpp11Accepted 40/4017ms4812 KiB
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<cassert>
#include<cassert>
#include<unordered_map>
#include<unordered_set>
#include<functional>
#include<queue>
#include<stack>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<sstream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<numeric>
#include<random>
#include<chrono>
#include<bitset>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define all(x) (x).begin(), (x).end()
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define sz(x) (int)(x).size()
#define gc getchar
#define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mp make_pair
#define ins insert

#ifndef ONLINE_JUDGE
#  define LOG(x) (cerr << #x << " = " << (x) << endl)
#else
#  define LOG(x) ((void)0)
#endif

using ll = long long;
using ull = unsigned long long ;
using ld = long double ;
using str = string;
using ordered_set=tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update>;

const double PI=acos(-1);
const ll INF = 1LL<<62;
const ll MINF = -(1LL<<62);

template<typename T> T getint() {
	T val=0;
	char c;
	
	bool neg=false;
	while((c=gc()) && !(c>='0' && c<='9')) {
		neg|=c=='-';
	}

	do {
		val=(val*10)+c-'0';
	} while((c=gc()) && (c>='0' && c<='9'));

	return val*(neg?-1:1);
}

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); uniform_int_distribution<int>(0, n-1)(rng)


int main() {
	IO;
	int n;
	cin>>n;
	vector<int> t(n);
	for(int i=0;i<n;++i) cin>>t[i];
	
	vector<int> keys(n);
	vector<int> key_lst;
	int pos=0, restarts=0;
	
	while(pos<n) {
		int curr=(t[pos]+restarts)%n;
		if(!keys[curr]) key_lst.pb(curr);
		keys[curr]=1;
		
		if(keys[pos]) pos++;
		else {
			vector<int> nkey_lst;
			for(int i:key_lst) {
				int akt=(i+1)%n;
				if(!keys[akt]) {
					keys[akt]=1;
					nkey_lst.pb(akt);
				}
			}
			
			key_lst.swap(nkey_lst);
			
			restarts++;
		}
	}
	
	cout<<restarts<<"\n";
	
	return 0;
}

SubtaskSumTestVerdictTimeMemory
base40/40
1Accepted0/03ms1828 KiB
2Accepted0/08ms2712 KiB
3Accepted2/22ms2348 KiB
4Accepted2/22ms2468 KiB
5Accepted2/22ms2668 KiB
6Accepted2/22ms2748 KiB
7Accepted2/22ms2912 KiB
8Accepted2/22ms2828 KiB
9Accepted2/22ms2956 KiB
10Accepted2/22ms2928 KiB
11Accepted2/216ms4156 KiB
12Accepted2/214ms4416 KiB
13Accepted2/216ms4724 KiB
14Accepted2/214ms4672 KiB
15Accepted2/214ms4612 KiB
16Accepted2/216ms4612 KiB
17Accepted2/217ms4612 KiB
18Accepted2/216ms4812 KiB
19Accepted2/214ms4756 KiB
20Accepted2/214ms4760 KiB
21Accepted2/217ms4808 KiB
22Accepted2/214ms4812 KiB