Submission #171828

# Submission time Handle Problem Language Result Execution time Memory
171828 2019-12-30T13:02:39 Z RafaelSus Nice sequence (IZhO18_sequence) C++14
15 / 100
10 ms 1016 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<<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++){
        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: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++){
                   ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Ok
2 Correct 2 ms 376 KB Ok
3 Correct 2 ms 376 KB Ok
4 Correct 2 ms 376 KB Ok
5 Correct 2 ms 380 KB Ok
6 Correct 2 ms 376 KB Ok
7 Correct 2 ms 376 KB Ok
8 Correct 2 ms 380 KB Ok
9 Correct 2 ms 376 KB Ok
10 Correct 3 ms 376 KB Ok
11 Correct 2 ms 376 KB Ok
12 Correct 2 ms 376 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Ok
2 Correct 2 ms 504 KB Ok
3 Correct 2 ms 376 KB Ok
4 Correct 2 ms 376 KB Ok
5 Correct 2 ms 376 KB Ok
6 Correct 3 ms 376 KB Ok
7 Correct 9 ms 888 KB Ok
8 Correct 5 ms 632 KB Ok
9 Correct 10 ms 1016 KB Ok
10 Correct 7 ms 760 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Ok
2 Correct 2 ms 376 KB Ok
3 Correct 2 ms 376 KB Ok
4 Incorrect 2 ms 376 KB Jury has the better answer : jans = 9, pans = 8
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Jury has the better answer : jans = 5, pans = 4
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Ok
2 Correct 2 ms 376 KB Ok
3 Correct 2 ms 376 KB Ok
4 Correct 2 ms 376 KB Ok
5 Correct 2 ms 380 KB Ok
6 Correct 2 ms 376 KB Ok
7 Correct 2 ms 376 KB Ok
8 Correct 2 ms 380 KB Ok
9 Correct 2 ms 376 KB Ok
10 Correct 3 ms 376 KB Ok
11 Correct 2 ms 376 KB Ok
12 Correct 2 ms 376 KB Ok
13 Correct 2 ms 376 KB Ok
14 Correct 2 ms 376 KB Ok
15 Correct 2 ms 376 KB Ok
16 Incorrect 2 ms 376 KB Jury has the better answer : jans = 9, pans = 8
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Ok
2 Correct 2 ms 376 KB Ok
3 Correct 2 ms 376 KB Ok
4 Correct 2 ms 376 KB Ok
5 Correct 2 ms 380 KB Ok
6 Correct 2 ms 376 KB Ok
7 Correct 2 ms 376 KB Ok
8 Correct 2 ms 380 KB Ok
9 Correct 2 ms 376 KB Ok
10 Correct 3 ms 376 KB Ok
11 Correct 2 ms 376 KB Ok
12 Correct 2 ms 376 KB Ok
13 Correct 2 ms 376 KB Ok
14 Correct 2 ms 504 KB Ok
15 Correct 2 ms 376 KB Ok
16 Correct 2 ms 376 KB Ok
17 Correct 2 ms 376 KB Ok
18 Correct 3 ms 376 KB Ok
19 Correct 9 ms 888 KB Ok
20 Correct 5 ms 632 KB Ok
21 Correct 10 ms 1016 KB Ok
22 Correct 7 ms 760 KB Ok
23 Correct 2 ms 376 KB Ok
24 Correct 2 ms 376 KB Ok
25 Correct 2 ms 376 KB Ok
26 Incorrect 2 ms 376 KB Jury has the better answer : jans = 9, pans = 8
27 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Ok
2 Correct 2 ms 376 KB Ok
3 Correct 2 ms 376 KB Ok
4 Correct 2 ms 376 KB Ok
5 Correct 2 ms 380 KB Ok
6 Correct 2 ms 376 KB Ok
7 Correct 2 ms 376 KB Ok
8 Correct 2 ms 380 KB Ok
9 Correct 2 ms 376 KB Ok
10 Correct 3 ms 376 KB Ok
11 Correct 2 ms 376 KB Ok
12 Correct 2 ms 376 KB Ok
13 Correct 2 ms 376 KB Ok
14 Correct 2 ms 504 KB Ok
15 Correct 2 ms 376 KB Ok
16 Correct 2 ms 376 KB Ok
17 Correct 2 ms 376 KB Ok
18 Correct 3 ms 376 KB Ok
19 Correct 9 ms 888 KB Ok
20 Correct 5 ms 632 KB Ok
21 Correct 10 ms 1016 KB Ok
22 Correct 7 ms 760 KB Ok
23 Correct 2 ms 376 KB Ok
24 Correct 2 ms 376 KB Ok
25 Correct 2 ms 376 KB Ok
26 Incorrect 2 ms 376 KB Jury has the better answer : jans = 9, pans = 8
27 Halted 0 ms 0 KB -