Submission #171830

# Submission time Handle Problem Language Result Execution time Memory
171830 2019-12-30T13:07:32 Z RafaelSus Nice sequence (IZhO18_sequence) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
 
using namespace std;
const int N = 2e5 + 5;
typedef long long ll;
const ll inf=1e15;
#define pb push_back
const int INF=(0x3f3f3f3f);
 
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);cout.tie(0);
 
  int t;
  cin>>t;
  
  while(t-->0){
    int n,m;
    cin>>n>>m;
    if(max(n,m)%min(n,m)==0){
      cout<<max(n,m)-1<<'\n';
      int x=-1;
      if(n==max(n,m))x=1;
      for(int i=0;i<max(n,m)-1;i++)cout<<(i+1)*x<<' ';
      cout<<'\n';
    }else if(min(n,m)==2){
      cout<<max(n,m)<<'\n';
      int x=-1;
      if(n==2)x=1;
      int tmp=max(n,m);
      int tm=(max(n,m)+1)*(-1);
      vector<int>answ;
      for(int i=0;i<max(n,m);i++){
        if(i%2==0){
          answ.pb(tmp);
          tmp--;
        }else{
          answ.pb(tm);
          tm++;
        }
      }
      for(int i=0;i<answ.size();i++){
        cout<<answ[i]*x<<' ';
      }
      cout<<'\n';
    }else{
     /* if(n>m)
        while(__gcd(n,m)!=1)n--;
      else 
        while(__gcd(n,m)!=1)m--;*/
      cout<<n+m-gcd(n,m)-1<<'\n';
      int x=-1;
      if(n==2)x=1;
      int tmp=max(n,m);
      int tm=(max(n,m)+1)*(-1);
      vector<int>answ;
      for(int i=0;i<n+m-gcd(n,m)-1;i++){
        if(i%2==0){
          answ.pb(tmp);
          tmp--;
        }else{
          answ.pb(tm);
          tm++;
        }
      }
      for(int i=0;i<answ.size();i++){
        answ[i]*=x;
      }
      int su=0;
      for(int i=0;i<min(n,m);i++){
        su+=answ[i];
      }
      if(n<m&&su>0){
        for(int i=0;i<answ.size();i++){
          answ[i]*=-1;
        }
      }else if(n>m&&su<0){
        for(int i=0;i<answ.size();i++){
          answ[i]*=-1;
        }
      }
      for(int i=0;i<answ.size();i++){
        cout<<answ[i]<<' ';
      }
      cout<<'\n';
    }
  }
}

Compilation message

sequence.cpp: In function 'int main()':
sequence.cpp:42:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
       for(int i=0;i<answ.size();i++){
                   ~^~~~~~~~~~~~
sequence.cpp:51:17: error: 'gcd' was not declared in this scope
       cout<<n+m-gcd(n,m)-1<<'\n';
                 ^~~
sequence.cpp:51:17: note: suggested alternative: 'gcvt'
       cout<<n+m-gcd(n,m)-1<<'\n';
                 ^~~
                 gcvt
sequence.cpp:66:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
       for(int i=0;i<answ.size();i++){
                   ~^~~~~~~~~~~~
sequence.cpp:74:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int i=0;i<answ.size();i++){
                     ~^~~~~~~~~~~~
sequence.cpp:78:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int i=0;i<answ.size();i++){
                     ~^~~~~~~~~~~~
sequence.cpp:82:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
       for(int i=0;i<answ.size();i++){
                   ~^~~~~~~~~~~~