Submission #255345

# Submission time Handle Problem Language Result Execution time Memory
255345 2020-07-31T18:02:10 Z uacoder123 Xylophone (JOI18_xylophone) C++14
100 / 100
134 ms 1032 KB
#include <cstdio>
#include <cstdlib>
#include <bits/stdc++.h>
#include "xylophone.h"
using namespace std;
#define F first
#define S second
#define FOR(i,a,b) for (auto i = (a); i <= (b); ++i)
#define NFOR(i,a,b) for(auto i = (a); i >= (b); --i)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define mp(i,a) make_pair(i,a)
#define pb(a) push_back(a)
#define bit(x,b) (x&(1LL<<b))

typedef long long int lli;
typedef pair <lli,lli> ii;
typedef pair <lli,ii> iii;
typedef vector <lli> vi;

void solve(int N) 
{
  int n=N;
  int arr[n],arr1[n];
  for(int i=1;i<n;++i)
    arr[i]=query(i,i+1);
  for(int i=1;i<n-1;++i)
    arr1[i]=query(i,i+2);
  int l=1,l1=0,mi=0,mi1=0;
  int arr2[n+1],arr3[n+1];
  arr2[1]=0;
  arr2[2]=arr[1];
  arr3[1]=0;
  arr3[2]=-arr[1];
  for(int i=2;i<n;++i)
  {
    if(arr1[i-1]!=arr[i-1]+arr[i])
    {
      if(l==1)
        arr2[i+1]=arr2[i]-arr[i];
      else
        arr2[i+1]=arr2[i]+arr[i];
      l^=1;
    }
    else
    {
    if(l==1)
        arr2[i+1]=arr2[i]+arr[i];
      else
        arr2[i+1]=arr2[i]-arr[i]; 
    }
    if(arr1[i-1]!=arr[i-1]+arr[i])
    {
      if(l1==1)
        arr3[i+1]=arr3[i]-arr[i];
      else
        arr3[i+1]=arr3[i]+arr[i];
      l1^=1;
    }
    else
    {
    if(l1==1)
        arr3[i+1]=arr3[i]+arr[i];
      else
        arr3[i+1]=arr3[i]-arr[i]; 
    }
  }
  for(int i=1;i<=n;++i)
  {
    mi=min(mi,arr2[i]);
    mi1=min(mi1,arr3[i]);
  }
  mi=-mi;
  mi1=-mi1;
  mi++;
  mi1++;
  ii f,s;
  int ch=1,ch1=1;
  set<int> se,se1;
  for(int i=1;i<=n;++i)
  {
    arr2[i]+=mi;
    se.insert(arr2[i]);
    arr3[i]+=mi1;
    se1.insert(arr3[i]);
    if(arr2[i]==1)
      f.F=i;
    else if(arr2[i]==n)
      f.S=i;
    if(arr3[i]==1)
      s.F=i;
    else if(arr3[i]==n)
      s.S=i;
  }
  if(se.size()!=n||(*(--se.end()))!=n)
    ch=0;
  if(se1.size()!=n||(*(--se1.end()))!=n)
    ch1=0;
  if(ch==1&&ch1==1)
  {
    if(f.F==s.F)
    {
      int r;
      if(s.S>=f.S)
      {
        r=query(min(f.F,f.S),max(f.F,f.S));
        if(r==n-1)
          ch1=0;
        else
          ch=0;
      }
      else
      {
      r=query(min(s.F,s.S),max(s.F,s.S));
        if(r==n-1)
          ch=0;
        else
          ch1=0;  
      }
    }
    else
    {
      int r=query(min(max(f,s).F,max(f,s).S),max(max(f,s).F,max(f,s).S));
      if(max(f,s)==f)
      {
        if(r==n-1)
          ch1=0;
        else
          ch=0;
      }
      else
      {
      if(r==n-1)
          ch=0;
        else
          ch1=0;  
      }
    }
  }
  if(ch==0)
  {
    for(int i=1;i<=n;++i)
      answer(i,arr2[i]);
  }
  else
  {
  for(int i=1;i<=n;++i)
      answer(i,arr3[i]);  
  }
}

Compilation message

xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:95:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if(se.size()!=n||(*(--se.end()))!=n)
      ~~~~~~~~~^~~
xylophone.cpp:97:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if(se1.size()!=n||(*(--se1.end()))!=n)
      ~~~~~~~~~~^~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 3 ms 256 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 3 ms 256 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 3 ms 256 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 3 ms 256 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 3 ms 256 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 3 ms 256 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 3 ms 256 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 3 ms 256 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 256 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 8 ms 384 KB Output is correct
18 Correct 19 ms 376 KB Output is correct
19 Correct 29 ms 376 KB Output is correct
20 Correct 11 ms 372 KB Output is correct
21 Correct 16 ms 376 KB Output is correct
22 Correct 21 ms 376 KB Output is correct
23 Correct 15 ms 376 KB Output is correct
24 Correct 15 ms 376 KB Output is correct
25 Correct 23 ms 376 KB Output is correct
26 Correct 18 ms 376 KB Output is correct
27 Correct 15 ms 376 KB Output is correct
28 Correct 18 ms 376 KB Output is correct
29 Correct 14 ms 376 KB Output is correct
30 Correct 17 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 3 ms 256 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 3 ms 256 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 3 ms 256 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 3 ms 256 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 256 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 8 ms 384 KB Output is correct
18 Correct 19 ms 376 KB Output is correct
19 Correct 29 ms 376 KB Output is correct
20 Correct 11 ms 372 KB Output is correct
21 Correct 16 ms 376 KB Output is correct
22 Correct 21 ms 376 KB Output is correct
23 Correct 15 ms 376 KB Output is correct
24 Correct 15 ms 376 KB Output is correct
25 Correct 23 ms 376 KB Output is correct
26 Correct 18 ms 376 KB Output is correct
27 Correct 15 ms 376 KB Output is correct
28 Correct 18 ms 376 KB Output is correct
29 Correct 14 ms 376 KB Output is correct
30 Correct 17 ms 376 KB Output is correct
31 Correct 54 ms 632 KB Output is correct
32 Correct 53 ms 632 KB Output is correct
33 Correct 74 ms 760 KB Output is correct
34 Correct 128 ms 896 KB Output is correct
35 Correct 90 ms 888 KB Output is correct
36 Correct 92 ms 900 KB Output is correct
37 Correct 119 ms 1016 KB Output is correct
38 Correct 127 ms 888 KB Output is correct
39 Correct 80 ms 900 KB Output is correct
40 Correct 118 ms 1032 KB Output is correct
41 Correct 129 ms 1016 KB Output is correct
42 Correct 85 ms 1016 KB Output is correct
43 Correct 99 ms 1020 KB Output is correct
44 Correct 126 ms 1028 KB Output is correct
45 Correct 98 ms 1024 KB Output is correct
46 Correct 83 ms 900 KB Output is correct
47 Correct 58 ms 888 KB Output is correct
48 Correct 58 ms 888 KB Output is correct
49 Correct 104 ms 1016 KB Output is correct
50 Correct 84 ms 888 KB Output is correct
51 Correct 61 ms 888 KB Output is correct
52 Correct 83 ms 1016 KB Output is correct
53 Correct 87 ms 888 KB Output is correct
54 Correct 106 ms 912 KB Output is correct
55 Correct 102 ms 900 KB Output is correct
56 Correct 134 ms 892 KB Output is correct
57 Correct 86 ms 888 KB Output is correct
58 Correct 99 ms 908 KB Output is correct
59 Correct 82 ms 888 KB Output is correct
60 Correct 90 ms 1016 KB Output is correct