Submission #103736

#TimeUsernameProblemLanguageResultExecution timeMemory
103736ekremZalmoxis (BOI18_zalmoxis)C++98
0 / 100
1091 ms86288 KiB
#include <bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define mod 1000000007
#define N 1000005
using namespace std;

typedef long long ll;
typedef pair < int , int > ii;

int n, k, m, a[N], b[N], bas[N], son[N];
ii ans;
set < ii > s, q;
set < ii > :: iterator it;
vector < int > g[N];

int main() {
	// freopen("in.txt", "r", stdin);
	// freopen("out.txt", "w", stdout);
	scanf("%d %d",&n ,&k);
	for(int i = 1; i <= n; i++){
		scanf("%d",a + i);
		g[a[i]].pb(i);
		bas[i] = i;
		son[i] = i;
	}
	for(int i = 1; i <= 30; i++){
		sort(g[i].begin(), g[i].end());
		for(int j = 0; j < g[i].size(); j++)
			if(j < (int)g[i].size() - 1 and son[g[i][j]] == bas[g[i][j + 1]]){
				g[i + 1].pb(g[i][j + 1]);
				bas[g[i][j + 1]] = bas[g[i][j]];
			} else{
				ans = mp(g[i][j], a[g[i][j]]);
				g[i + 1].pb(g[i][j]);
			}
	}
	for(int i = 1; i <= n; i++){
		printf("%d ", a[i]);
		if(i == ans.st)
			printf("%d ", ans.nd);
	}
	return 0;
}

Compilation message (stderr)

zalmoxis.cpp: In function 'int main()':
zalmoxis.cpp:31:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int j = 0; j < g[i].size(); j++)
                  ~~^~~~~~~~~~~~~
zalmoxis.cpp:22:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d",&n ,&k);
  ~~~~~^~~~~~~~~~~~~~~~
zalmoxis.cpp:24:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",a + i);
   ~~~~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...