답안 #114980

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
114980 2019-06-04T09:15:16 Z IVIosab Xylophone (JOI18_xylophone) C++17
100 / 100
108 ms 1088 KB
#include "xylophone.h"
#include <bits/stdc++.h>
using namespace std;

int a[5005];
int a1[5005],a2[5005];

void solve(int N) {
    int n=N;
    int value = n-1;
    map<pair<int,int>,int> mp;
    for(int i=1;i<n;i++){
        int t=query(i,i+1);
        mp[{i,i+1}]=t;
    }
    for(int i=1;i<n-1;i++){
        int t=query(i,i+2);
        if(mp[{i,i+1}]+mp[{i+1,i+2}]==t){
            mp[{i,i+2}]=1;
        }
    }
    a1[1]=0;
    a2[1]=0;
    int mn1=0,mn2=0;
    for(int i=2;i<=n;i++){
        int t=mp[{i-1,i}];
        if(i==2){
            a1[i]=mp[{1,2}];
            a2[i]=-mp[{1,2}];
        }
        else{
            if(mp[{i-2,i}]){
                if(a1[i-2]>a1[i-1]){
                    a1[i]=a1[i-1]-t;
                }
                else{
                    a1[i]=a1[i-1]+t;
                }
                if(a2[i-2]>a2[i-1]){
                    a2[i]=a2[i-1]-t;
                }
                else{
                    a2[i]=a2[i-1]+t;
                }
            }
            else{
                if(a1[i-2]>a1[i-1]){
                    a1[i]=a1[i-1]+t;
                }
                else{
                    a1[i]=a1[i-1]-t;
                }
                if(a2[i-2]>a2[i-1]){
                    a2[i]=a2[i-1]+t;
                }
                else{
                    a2[i]=a2[i-1]-t;
                }
            }
        }
        mn1=min(mn1,a1[i]);
        mn2=min(mn2,a2[i]);
    }
    int m1=1e9,mx1=0,m2=1e9,mx2=0,im1=0,ix1=0,im2=0,ix2=0;
    for(int i=1;i<=n;i++){
        a1[i]+=abs(mn1)+1;
        a2[i]+=abs(mn2)+1;
        if(a1[i]<m1){
            m1=a1[i];
            im1=i;
        }
        if(a1[i]>mx1){
            mx1=a1[i];
            ix1=i;
        }
    }
    if(im1<ix1){
        for(int i=1;i<=n;i++){
            answer(i,a1[i]);
        }
    }
    else{
        for(int i=1;i<=n;i++){
            answer(i,a2[i]);
        }
    }
}

Compilation message

xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:10:9: warning: unused variable 'value' [-Wunused-variable]
     int value = n-1;
         ^~~~~
xylophone.cpp:64:22: warning: unused variable 'm2' [-Wunused-variable]
     int m1=1e9,mx1=0,m2=1e9,mx2=0,im1=0,ix1=0,im2=0,ix2=0;
                      ^~
xylophone.cpp:64:29: warning: unused variable 'mx2' [-Wunused-variable]
     int m1=1e9,mx1=0,m2=1e9,mx2=0,im1=0,ix1=0,im2=0,ix2=0;
                             ^~~
xylophone.cpp:64:47: warning: unused variable 'im2' [-Wunused-variable]
     int m1=1e9,mx1=0,m2=1e9,mx2=0,im1=0,ix1=0,im2=0,ix2=0;
                                               ^~~
xylophone.cpp:64:53: warning: unused variable 'ix2' [-Wunused-variable]
     int m1=1e9,mx1=0,m2=1e9,mx2=0,im1=0,ix1=0,im2=0,ix2=0;
                                                     ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 3 ms 256 KB Output is correct
4 Correct 4 ms 256 KB Output is correct
5 Correct 6 ms 256 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 6 ms 384 KB Output is correct
8 Correct 5 ms 256 KB Output is correct
9 Correct 3 ms 256 KB Output is correct
10 Correct 5 ms 256 KB Output is correct
11 Correct 4 ms 256 KB Output is correct
12 Correct 4 ms 256 KB Output is correct
13 Correct 3 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 4 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 3 ms 256 KB Output is correct
4 Correct 4 ms 256 KB Output is correct
5 Correct 6 ms 256 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 6 ms 384 KB Output is correct
8 Correct 5 ms 256 KB Output is correct
9 Correct 3 ms 256 KB Output is correct
10 Correct 5 ms 256 KB Output is correct
11 Correct 4 ms 256 KB Output is correct
12 Correct 4 ms 256 KB Output is correct
13 Correct 3 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 4 ms 256 KB Output is correct
16 Correct 5 ms 256 KB Output is correct
17 Correct 10 ms 376 KB Output is correct
18 Correct 15 ms 424 KB Output is correct
19 Correct 20 ms 376 KB Output is correct
20 Correct 21 ms 376 KB Output is correct
21 Correct 10 ms 448 KB Output is correct
22 Correct 25 ms 528 KB Output is correct
23 Correct 26 ms 384 KB Output is correct
24 Correct 21 ms 424 KB Output is correct
25 Correct 21 ms 376 KB Output is correct
26 Correct 16 ms 504 KB Output is correct
27 Correct 24 ms 376 KB Output is correct
28 Correct 22 ms 424 KB Output is correct
29 Correct 22 ms 376 KB Output is correct
30 Correct 21 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 3 ms 256 KB Output is correct
4 Correct 4 ms 256 KB Output is correct
5 Correct 6 ms 256 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 6 ms 384 KB Output is correct
8 Correct 5 ms 256 KB Output is correct
9 Correct 3 ms 256 KB Output is correct
10 Correct 5 ms 256 KB Output is correct
11 Correct 4 ms 256 KB Output is correct
12 Correct 4 ms 256 KB Output is correct
13 Correct 3 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 4 ms 256 KB Output is correct
16 Correct 5 ms 256 KB Output is correct
17 Correct 10 ms 376 KB Output is correct
18 Correct 15 ms 424 KB Output is correct
19 Correct 20 ms 376 KB Output is correct
20 Correct 21 ms 376 KB Output is correct
21 Correct 10 ms 448 KB Output is correct
22 Correct 25 ms 528 KB Output is correct
23 Correct 26 ms 384 KB Output is correct
24 Correct 21 ms 424 KB Output is correct
25 Correct 21 ms 376 KB Output is correct
26 Correct 16 ms 504 KB Output is correct
27 Correct 24 ms 376 KB Output is correct
28 Correct 22 ms 424 KB Output is correct
29 Correct 22 ms 376 KB Output is correct
30 Correct 21 ms 504 KB Output is correct
31 Correct 37 ms 528 KB Output is correct
32 Correct 50 ms 736 KB Output is correct
33 Correct 103 ms 888 KB Output is correct
34 Correct 61 ms 888 KB Output is correct
35 Correct 76 ms 1008 KB Output is correct
36 Correct 83 ms 1016 KB Output is correct
37 Correct 64 ms 936 KB Output is correct
38 Correct 108 ms 960 KB Output is correct
39 Correct 108 ms 904 KB Output is correct
40 Correct 100 ms 936 KB Output is correct
41 Correct 101 ms 992 KB Output is correct
42 Correct 48 ms 968 KB Output is correct
43 Correct 77 ms 1000 KB Output is correct
44 Correct 103 ms 888 KB Output is correct
45 Correct 83 ms 960 KB Output is correct
46 Correct 80 ms 876 KB Output is correct
47 Correct 71 ms 1040 KB Output is correct
48 Correct 98 ms 936 KB Output is correct
49 Correct 108 ms 888 KB Output is correct
50 Correct 92 ms 1088 KB Output is correct
51 Correct 71 ms 888 KB Output is correct
52 Correct 67 ms 1060 KB Output is correct
53 Correct 64 ms 884 KB Output is correct
54 Correct 81 ms 876 KB Output is correct
55 Correct 99 ms 1016 KB Output is correct
56 Correct 60 ms 888 KB Output is correct
57 Correct 63 ms 868 KB Output is correct
58 Correct 103 ms 1032 KB Output is correct
59 Correct 59 ms 1040 KB Output is correct
60 Correct 103 ms 1016 KB Output is correct