답안 #474675

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
474675 2021-09-19T11:08:03 Z Mr_OK_Man Knjige (COCI20_knjige) C++17
25 / 50
45 ms 2680 KB
#include <bits/stdc++.h>

using namespace std;

int main()
{
    long long n,q=0;
    cin>>n;
     stack<long long>l,d;
    vector<string >ans1,ans2,ans3;
    long long p[n],b[n];
    for(int i=0;i<n;i++)
    {
        cin>>p[i];

        b[i]=p[i];
    }
    for(int i=n-1;i>=0;i--)
    {
        l.push(p[i]);
    }
    sort(b,b+n);
    for(int i=0;i<n;i++)
    {
        if(b[i]==p[i])q++;
    }
    if(q==n)
    {cout<<0<<endl;

    return 0;

    }
    long long h=n-1,c=0;
    long long m=0,k=0;
     long long r=1;
    while(h>=0)
    {
        while(l.empty()==0)
        {
              c++;
            if(l.top()==b[h]&&h==n-1)
            {
                ans1.push_back("UZMI");
                ans2.push_back("L");
                ans3.push_back("L");
        /*    cout<<"UZMI"<<" ";
            cout<<"L"<<" "<<"L";*/
            l.pop();
            r=0;
                continue;
            }
           // cout<<l.top()<<endl;
          ans1.push_back("UZMI");
          ans2.push_back("D");
          ans3.push_back("L");
           /* cout<<"UZMI"<<" ";
            cout<<"D"<<" "<<"L";*/
            c++;
            ans1.push_back("STAVI");
          ans2.push_back("D");
          ans3.push_back("D");
          /*
            cout<<"STAVI"<<" ";
            cout<<"D"<<" "<<"D";*/
            d.push(l.top());
            l.pop();
        }
       c++;
        ans1.push_back("STAVI");
        ans2.push_back("L");
        ans3.push_back("L");
         h--;
           /* cout<<"STAVI"<<" ";
            cout<<"L"<<" "<<"L";*/
    if(h==-1)
    {
        break;
    }
     long long g=1;
        while(d.empty()==0)
        {
              c++;
            if(d.top()==b[h]&&g==1)
            {
                ans1.push_back("UZMI");
                ans2.push_back("L");
                ans3.push_back("D");
           /* cout<<"UZMI"<<" ";
            cout<<"L"<<" "<<"D";*/
            d.pop();
            g=0;
            continue;
            }
            /*cout<<h<<endl;
            cout<<d.top()<<endl;*/
           ans1.push_back("UZMI");
            ans2.push_back("D");
            ans3.push_back("D");
        /*    cout<<"UZMI"<<" ";
            cout<<"D"<<" "<<"D";*/
            c++;
        ans1.push_back("STAVI");
          ans2.push_back("D");
          ans3.push_back("L");
          /*
            cout<<"STAVI"<<" ";
            cout<<"D"<<" "<<"L";*/
            l.push(d.top());
            d.pop();
        }
    }/*
while(d.empty()==0)
        {
              c++;
                ans1.push_back("UZMI");
                ans2.push_back("D");
                ans3.push_back("D");
            cout<<"UZMI"<<" ";
            cout<<"D"<<" "<<"D";
                  ans1.push_back("STAVI");
          ans2.push_back("D");
          ans3.push_back("L");
            /*cout<<"STAVI"<<" ";
            cout<<"D"<<" "<<"L";
            d.pop();
        }*/
        cout<<c<<endl;
        for(int i=0;i<c;i++)
        {
            cout<<ans1[i]<<" "<<ans2[i]<<" "<<ans3[i]<<endl;
        }







    return 0;
}

Compilation message

Main.cpp:123:13: warning: "/*" within comment [-Wcomment]
  123 |             /*cout<<"STAVI"<<" ";
      |              
Main.cpp: In function 'int main()':
Main.cpp:34:15: warning: unused variable 'm' [-Wunused-variable]
   34 |     long long m=0,k=0;
      |               ^
Main.cpp:34:19: warning: unused variable 'k' [-Wunused-variable]
   34 |     long long m=0,k=0;
      |                   ^
Main.cpp:35:16: warning: variable 'r' set but not used [-Wunused-but-set-variable]
   35 |      long long r=1;
      |                ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 37 ms 2612 KB Cannot hold multiple books at one hand
2 Incorrect 38 ms 2612 KB Cannot hold multiple books at one hand
3 Incorrect 45 ms 2612 KB Cannot hold multiple books at one hand
4 Correct 39 ms 2612 KB Output is correct
5 Correct 37 ms 2612 KB Output is correct
6 Incorrect 43 ms 2612 KB Cannot hold multiple books at one hand
7 Incorrect 27 ms 2044 KB Cannot hold multiple books at one hand
8 Correct 37 ms 2600 KB Output is correct
9 Correct 38 ms 2680 KB Output is correct
10 Correct 37 ms 2612 KB Output is correct