답안 #474678

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
474678 2021-09-19T11:15:18 Z Mr_OK_Man Knjige (COCI20_knjige) C++17
50 / 50
44 ms 2636 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&&r==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;
      |                   ^
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 2612 KB Output is correct
2 Correct 37 ms 2612 KB Output is correct
3 Correct 38 ms 2612 KB Output is correct
4 Correct 38 ms 2572 KB Output is correct
5 Correct 37 ms 2612 KB Output is correct
6 Correct 37 ms 2620 KB Output is correct
7 Correct 37 ms 2612 KB Output is correct
8 Correct 37 ms 2612 KB Output is correct
9 Correct 37 ms 2636 KB Output is correct
10 Correct 44 ms 2612 KB Output is correct