結果

問題 No.318 学学学学学
ユーザー かに
提出日時 2015-12-11 02:14:10
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
TLE  
実行時間 -
コード長 1,252 bytes
コンパイル時間 1,503 ms
コンパイル使用メモリ 165,272 KB
実行使用メモリ 14,080 KB
最終ジャッジ日時 2024-09-15 07:50:20
合計ジャッジ時間 8,024 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample -- * 3
other AC * 5 TLE * 1 -- * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0;i < n;i++)
#define REP(i,n,k) for(int i = n;i < k;i++)
#define P(p) cout<<(p)<<endl;
#define pi 3.1415926535
using namespace std;
typedef long long ll;
int dx[] = { 0, 1, 0, -1 };
int dy[] = { -1, 0, 1, 0 };

unsigned long long sttoi(std::string str) {
	unsigned long long ret;
	std::stringstream ss; ss << str;
	ss >> ret;
	return ret;
}

ll gcd(ll a, ll b){
	if (b > a)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a%b);
}

void solve() {
	int n;
	cin >> n;
	int A[100000];
	int ans[100000];
	set<int> s;
	rep(i, n){
		cin >> A[i];
		ans[i] = A[i];
		s.insert(A[i]);
	}
	for (auto it = s.begin(); it != s.end(); it++){
		int f = -1, e = -1;
		rep(i, n){
			if (f != -1 && e != -1){
				for (int j = f; j <= e; j++){
					ans[j] = *it;
				}
				f = -1;
				e = -1;
			}
			if (A[i] == *it && f == -1){
				f = i;
			}
			else if (A[i] == *it && f != -1){
				e = i;
			}
		}
		if (f != -1 && e != -1){
			for (int i = f; i <= e; i++){
				ans[i] = *it;
			}
		}
		else if (f != -1){
			ans[f] = *it;
		}
	}
	rep(i, n){
		cout << ans[i];
		if (i != n - 1){
			cout << " ";
		}
	}
	cout << endl;
}

int main() {
	solve();
	return 0;
}
0