Submission #568988

# Submission time Handle Problem Language Result Execution time Memory
568988 2022-05-26T12:18:06 Z MilosMilutinovic Nice sequence (IZhO18_sequence) C++17
0 / 100
17 ms 19524 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;
	deque<int> q;
	rep(i,0,x+1) if (deg[i]==0) q.pb(i);
	while (!q.empty()) {
		int x=q[0];
		q.pop_front();
		v[x]=++t;
		for (int y:e[x]) {
			deg[y]--;
			if (deg[y]==0) q.pb(y);
		}
	}
	per(i,1,x+1) v[i]-=v[i-1];
	rep(i,1,x+1) printf("%d ",v[i]); 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]); 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]); 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",&_);_;_--) {
      |       ~~~~~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 17 ms 19524 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 15 ms 19508 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 13 ms 19488 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 13 ms 19500 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 17 ms 19524 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 17 ms 19524 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 17 ms 19524 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -