跳到正文

题解

题解 ARC115C【ℕ Coloring】

rui_er约 2 分钟
原文
文章信息与版本

文章信息

发布
2023年1月19日
收录
2026年10月13日
更新
2026年11月7日
篇幅
约 2 分钟
获赞
6

版本

  1. v1当前

显然 A1,A2,A4,A8,⋯A_1,A_2,A_4,A_8,\cdots 必须互不相同,因此最大的数一定不小于 ⌊log⁡2n⌋+1\lfloor\log_2n\rfloor+1,猜想可以取到 ⌊log⁡2n⌋+1\lfloor\log_2n\rfloor+1。

构造 Ai=⌊log⁡2i⌋+1A_i=\lfloor\log_2i\rfloor+1,则对于任意 Ai=AjA_i=A_j 都有 2i>j2i > j,不存在倍数关系。

时间复杂度 Θ(n)\Theta(n)。

C++
// Problem: C - ℕ Coloring
// Contest: AtCoder - AtCoder Regular Contest 115
// URL: https://atcoder.jp/contests/arc115/tasks/arc115_c
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

//By: OIer rui_er
#include <bits/stdc++.h>
#define rep(x,y,z) for(int x=(y);x<=(z);x++)
#define per(x,y,z) for(int x=(y);x>=(z);x--)
#define debug(format...) fprintf(stderr, format)
#define fileIO(s) do{freopen(s".in","r",stdin);freopen(s".out","w",stdout);}while(false)
using namespace std;
typedef long long ll;

template<typename T> void chkmin(T& x, T y) {if(x > y) x = y;}
template<typename T> void chkmax(T& x, T y) {if(x < y) x = y;}

int main() {
	int n;
	scanf("%d", &n);
	for(int L = 1, R, u = 1; L <= n; L = R + 1, u++) {
		R = 2 * L - 1;
		chkmin(R, n);
		rep(i, L, R) printf("%d%c", u, " \n"[i==n]);
	}
	return 0;
}
原文