結果

問題 No.2451 Redistribute Integers
ユーザー stella1225stella1225
提出日時 2023-09-20 00:58:08
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 212 ms / 2,000 ms
コード長 4,749 bytes
コンパイル時間 1,955 ms
コンパイル使用メモリ 176,264 KB
実行使用メモリ 5,152 KB
最終ジャッジ日時 2023-09-20 00:58:15
合計ジャッジ時間 7,249 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 212 ms
4,852 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 145 ms
5,152 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,384 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 64 ms
4,380 KB
testcase_13 AC 183 ms
4,884 KB
testcase_14 AC 200 ms
4,892 KB
testcase_15 AC 101 ms
4,376 KB
testcase_16 AC 87 ms
4,380 KB
testcase_17 AC 140 ms
4,376 KB
testcase_18 AC 188 ms
4,880 KB
testcase_19 AC 15 ms
4,376 KB
testcase_20 AC 151 ms
4,616 KB
testcase_21 AC 187 ms
4,972 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <assert.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
#define rep(i,a,n) for (int i = a; i < (n); i++)
//#define REP(m) for (int i = 0; i < (m); i++)
#define all(x) (x).begin(),(x).end()
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
using Grid = vector<vector<char>>;
int mod = 998244353;
int INF = 1001001001;
//cout << fixed << setprecision(15);

using vi = vector<int>;
using vc = vector<char>;
using vs = vector<string>;
using vll = vector<ll>;
using pii = pair<int, int>;
using pci = pair<char,int>;
using pic = pair<int,char>;
using pll = pair<ll, ll>;
using mii = map<int,int>;
using mci = map<char,int>;

int Flag=0;

//デフォルトでNoがでる
void yn(int Flag){
  if(Flag==1){
    cout<<"Yes"<<endl;
  }
  else if(Flag==0){
    cout<<"No"<<endl;
  }
  else{
    cout<<-1<<endl;
  }
}

//cerrGrid
void cerrGrid(vector<vector<char>> &V){
  int n=V.size();
  rep(i,0,n){
    for(auto x:V[i]){
      cerr<<x<<" ";
    }
    cerr<<endl;
  }
  cerr<<endl;
}

//cerrGraph
void cerrGraph(vector<vector<int>> &G){
	int n=G.size();
	rep(i,0,n){
    for(auto& vertex:G[i]){
      cerr<<vertex<<" ";
    }
    cerr<<endl;
  }
}

//cerrIntVec
void cerrIntVec(vector<int> &V){
  for(auto& v:V){
    cerr<<v<<endl;
  }
}

//UnionFind
class UnionFind
{
public:

	UnionFind() = default;

	/// @brief Union-Find 木を構築します。
	/// @param n 要素数
	explicit UnionFind(size_t n)
		: m_parentsOrSize(n, -1) {}

	/// @brief 頂点 i の root のインデックスを返します。
	/// @param i 調べる頂点のインデックス
	/// @return 頂点 i の root のインデックス
	int find(int i)
	{
		if (m_parentsOrSize[i] < 0)
		{
			return i;
		}

		// 経路圧縮
		return (m_parentsOrSize[i] = find(m_parentsOrSize[i]));
	}

	/// @brief a のグループと b のグループを統合します。
	/// @param a 一方のインデックス
	/// @param b 他方のインデックス
	void merge(int a, int b)
	{
		a = find(a);
		b = find(b);

		if (a != b)
		{
			// union by size (小さいほうが子になる)
			if (-m_parentsOrSize[a] < -m_parentsOrSize[b])
			{
				std::swap(a, b);
			}

			m_parentsOrSize[a] += m_parentsOrSize[b];
			m_parentsOrSize[b] = a;
		}
	}

	/// @brief a と b が同じグループに属すかを返します。
	/// @param a 一方のインデックス
	/// @param b 他方のインデックス
	/// @return a と b が同じグループに属す場合 true, それ以外の場合は false
	bool connected(int a, int b)
	{
		return (find(a) == find(b));
	}

	/// @brief i が属するグループの要素数を返します。
	/// @param i インデックス
	/// @return i が属するグループの要素数
	int size(int i)
	{
		return -m_parentsOrSize[find(i)];
	}

private:

	// m_parentsOrSize[i] は i の 親,
	// ただし root の場合は (-1 * そのグループに属する要素数)
	std::vector<int> m_parentsOrSize;
};

//通常dfs
void dfs(int now, vector<int> &seen, Graph &G){
    seen[now]=true;
    for(auto next:G[now]){
        if(seen[next]) continue;
        dfs(next, seen,G);
    }
}

//サイクル検出dfs
bool dfs(int now, vector<bool> &seen, vector<bool> &finished, Graph &G){
  bool res=1;
  seen[now]=1;
  for(auto nx:G[now]){
    if(seen[nx] && !finished[nx]){
      res=0;
      return res;
    }
    else if(seen[nx]){
      continue;
    }
    res&=dfs(nx, seen, finished, G);
  }
  finished[now]=1;
  return res;
}

//典型グラフ問題main関数
/*
int main(){
    int N,M; cin>>N>>M;
    Graph G(N);
    rep(i,0,M){
        int A,B; cin>>A>>B;
        A--; B--;
        G[A].push_back(B);
        G[B].push_back(A);
    }
}
*/

//2進数にする
string to_2(int K){
	string res;
	while(K>0){
		if(K%2==1){
			res+='1';
		}
		else{
			res+='0';
		}
		K/=2;
	}
	reverse(all(res));
	return res;
}

//N未満の素数を全列挙する関数
vector<ll> Eratosthenes( const int N ){
  //is_prime[i]がfalse->iは素数
  vector<int> is_prime(N+1);
  vector<ll> res;
  rep(i,2,N+1){
    if(is_prime[i]==false){
      for(int j=2*i; j<N+1; j+=i){
        is_prime[j]=true;
      }
      res.push_back(i);
    }
  }
  return res;
}

//mapの全要素を出力する
void cerrMapIntInt(map<int,int> mp){
	auto begin = mp.begin(), end = mp.end();
  for (auto iter = begin; iter != end; iter++) {
        // first: key, second: value
        cout << "key = " << iter->first << "\n";
        cout << "value = " << iter->second << "\n";
    }
}

int main(){
  int N; cin>>N;
  vector<int> A(N);
  rep(i,0,N) cin>>A[i];
  rep(i,0,N){
    A[i]+=1e9+2;
  }
  rep(i,0,N-1){
    if(A[i+1]%N!=A[i]%N){
      yn(0);
      return 0;
    }
  }
  yn(1);
}

      
    
0