제출 #941388

#제출 시각아이디문제언어결과실행 시간메모리
941388shoryu386Stone Arranging 2 (JOI23_ho_t1)C++17
60 / 100
2059 ms18672 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long

main(){
	int n; cin >> n;
	int arr[n]; for (int x = 0; x < n; x++) cin >> arr[x];
	
	stack<int> stk;
	unordered_multiset<int> valInStk;
	
	int res[n];
	for (int x = 0; x < n; x++){
		res[x] = arr[x];

		if (valInStk.find(res[x]) != valInStk.end()){
			vector<int> items;
			
			while (!stk.empty()){
				if ( res[stk.top()] == res[x]){
					break;
				}
				else{
					items.push_back(stk.top());
					valInStk.erase(valInStk.find(res[stk.top()]));
					stk.pop();
				}
			}
			
			for (auto y : items){
				res[y] = res[x];
				stk.push(y);
				valInStk.insert(res[y]);
			}
		}
		
		stk.push(x);
		valInStk.insert(res[x]);
	}
	
	for (int x = 0; x < n; x++) cout << res[x] << '\n';
}

컴파일 시 표준 에러 (stderr) 메시지

Main.cpp:6:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    6 | main(){
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...