답안 #568325

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
568325 2022-05-25T08:33:21 Z MilosMilutinovic Nice sequence (IZhO18_sequence) C++17
0 / 100
16 ms 19540 KB
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef basic_string<int> BI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
mt19937 mrand(random_device{}());
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head
 
const int N=400505;
int n,m,_,deg[N],v[N],t;
VI e[N];
 
bool check(int x) {
	rep(i,0,x+1) deg[i]=0,e[i].clear();
	rep(i,n,x+1) {
		e[i].pb(i-n);
		deg[i-n]++;
	}
	rep(i,m,x+1) {
		e[i-m].pb(i);
		deg[i]++;
	}
	t=0;
	queue<int> q;
	rep(i,0,x+1) if (deg[i]==0) q.push(i);
	while (SZ(q)) {
		int x=q.front();
		q.pop();
		v[x]=++t;
		for (int y:e[x]) {
			deg[y]--;
			if (deg[y]==0) q.push(y);
		}
	}
	per(i,1,x+1) v[i]-=v[i-1];
	rep(i,1,x+1) printf("%d ",v[i]); if (x!=0) printf("\n");
}
void solve() {
	scanf("%d%d",&n,&m);
	int ans=n+m-1-__gcd(n,m);
	printf("%d\n",ans);
	check(ans);
}
 
int main() {
	for (scanf("%d",&_);_;_--) {
		solve();
	}
	return 0;
}

Compilation message

sequence.cpp: In function 'bool check(int)':
sequence.cpp:3:20: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
    3 | #define rep(i,a,n) for (int i=a;i<n;i++)
      |                    ^~~
sequence.cpp:51:2: note: in expansion of macro 'rep'
   51 |  rep(i,1,x+1) printf("%d ",v[i]); if (x!=0) printf("\n");
      |  ^~~
sequence.cpp:51:35: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   51 |  rep(i,1,x+1) printf("%d ",v[i]); if (x!=0) printf("\n");
      |                                   ^~
sequence.cpp:52:1: warning: no return statement in function returning non-void [-Wreturn-type]
   52 | }
      | ^
sequence.cpp: In function 'void solve()':
sequence.cpp:54:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   54 |  scanf("%d%d",&n,&m);
      |  ~~~~~^~~~~~~~~~~~~~
sequence.cpp: In function 'int main()':
sequence.cpp:61:12: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   61 |  for (scanf("%d",&_);_;_--) {
      |       ~~~~~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 13 ms 19436 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 13 ms 19484 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 16 ms 19540 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 14 ms 19468 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 13 ms 19436 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 13 ms 19436 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 13 ms 19436 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -