Submission #714619

# Submission time Handle Problem Language Result Execution time Memory
714619 2023-03-25T06:41:58 Z Erkinoff_Mohammed Painting Walls (APIO20_paint) C++14
0 / 100
1 ms 212 KB
#include "bits/stdc++.h"
using namespace std;
#define ll long long
#define f(ii,qwe) for(ll i=ii;i<qwe;i++)
#define f2(ii,qwe) for(ll j=ii;j<qwe;j++)
#define INF 2000000001
#define INFLL 3000000000000000001LL

/*
 8
 3
 5
 3 3 1 3 4 4 2 2
 3 2 2
 0 1 2
 2 3
 3 4
 
 8
 5
 5
 0 1 2 3 4 0 1 2
 1 1 1 1 1
 0 1 2 3 4
 */

int minimumInstructions(int n, int m, int k, vector<int>c, vector<int>a, vector<vector<int>>b){
    map<int,int>mp;
    f(0,k){
        mp[i]=-1;
    }
    f(0,m){
        f2(0,a[i]){
            mp[b[i][j]]=i;
        }
    }
    set<int>beg;
    f(0,n){
        c[i]=mp[c[i]];
        if(c[i]==-1){
            return -1;
        }
    }
    f(0,n){
        if(c[i]==0){
            beg.insert(i);
        }
    }
    vector<pair<int,int>>vec;
    for(int i:beg){
        int cur=i+1;
        bool b=1;
        int mx=i+m;
        bool b2=1;
        f2(1,m){
            if(cur<n&&c[cur]==j);
            else if(b&&cur-m>=0&&c[cur-m]==j){
                b=0;
                mx=cur;
                cur-=m;
            }
            else{
                b2=0;
                break;
            }
            cur++;
        }
        if(b2){
            vec.push_back({mx-m,mx});
        }
    }
    int cur=0;
    int ret=0;
    f(0,vec.size()){
        if(i<vec.size()-1&&vec[i+1].first<=cur)continue;
        if(vec[i].first<=cur){
            cur=vec[i].second;
            ret++;
        }
        else{
            return -1;
        }
    }
    if(cur!=n)return -1;
    return ret;
}

Compilation message

paint.cpp: In function 'int minimumInstructions(int, int, int, std::vector<int>, std::vector<int>, std::vector<std::vector<int> >)':
paint.cpp:4:32: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    4 | #define f(ii,qwe) for(ll i=ii;i<qwe;i++)
      |                               ~^~~~~~~~~
    5 | #define f2(ii,qwe) for(ll j=ii;j<qwe;j++)
      | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    6 | #define INF 2000000001
      | ~~~~~~~~~~~~~~~~~~~~~~          
    7 | #define INFLL 3000000000000000001LL
      | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    8 | 
      |                                 
    9 | /*
      | ~~                              
   10 |  8
      |  ~                              
   11 |  3
      |  ~                              
   12 |  5
      |  ~                              
   13 |  3 3 1 3 4 4 2 2
      |  ~~~~~~~~~~~~~~~                
   14 |  3 2 2
      |  ~~~~~                          
   15 |  0 1 2
      |  ~~~~~                          
   16 |  2 3
      |  ~~~                            
   17 |  3 4
      |  ~~~                            
   18 | 
      |                                 
   19 |  8
      |  ~                              
   20 |  5
      |  ~                              
   21 |  5
      |  ~                              
   22 |  0 1 2 3 4 0 1 2
      |  ~~~~~~~~~~~~~~~                
   23 |  1 1 1 1 1
      |  ~~~~~~~~~                      
   24 |  0 1 2 3 4
      |  ~~~~~~~~~                      
   25 |  */
      |  ~~                             
   26 | 
      |                                 
   27 | int minimumInstructions(int n, int m, int k, vector<int>c, vector<int>a, vector<vector<int>>b){
      | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   28 |     map<int,int>mp;
      |     ~~~~~~~~~~~~~~~             
   29 |     f(0,k){
      |     ~~~~~~~                     
   30 |         mp[i]=-1;
      |         ~~~~~~~~~               
   31 |     }
      |     ~                           
   32 |     f(0,m){
      |     ~~~~~~~                     
   33 |         f2(0,a[i]){
      |         ~~~~~~~~~~~             
   34 |             mp[b[i][j]]=i;
      |             ~~~~~~~~~~~~~~      
   35 |         }
      |         ~                       
   36 |     }
      |     ~                           
   37 |     set<int>beg;
      |     ~~~~~~~~~~~~                
   38 |     f(0,n){
      |     ~~~~~~~                     
   39 |         c[i]=mp[c[i]];
      |         ~~~~~~~~~~~~~~          
   40 |         if(c[i]==-1){
      |         ~~~~~~~~~~~~~           
   41 |             return -1;
      |             ~~~~~~~~~~          
   42 |         }
      |         ~                       
   43 |     }
      |     ~                           
   44 |     f(0,n){
      |     ~~~~~~~                     
   45 |         if(c[i]==0){
      |         ~~~~~~~~~~~~            
   46 |             beg.insert(i);
      |             ~~~~~~~~~~~~~~      
   47 |         }
      |         ~                       
   48 |     }
      |     ~                           
   49 |     vector<pair<int,int>>vec;
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~   
   50 |     for(int i:beg){
      |     ~~~~~~~~~~~~~~~             
   51 |         int cur=i+1;
      |         ~~~~~~~~~~~~            
   52 |         bool b=1;
      |         ~~~~~~~~~               
   53 |         int mx=i+m;
      |         ~~~~~~~~~~~             
   54 |         bool b2=1;
      |         ~~~~~~~~~~              
   55 |         f2(1,m){
      |         ~~~~~~~~                
   56 |             if(cur<n&&c[cur]==j);
      |             ~~~~~~~~~~~~~~~~~~~~~
   57 |             else if(b&&cur-m>=0&&c[cur-m]==j){
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   58 |                 b=0;
      |                 ~~~~            
   59 |                 mx=cur;
      |                 ~~~~~~~         
   60 |                 cur-=m;
      |                 ~~~~~~~         
   61 |             }
      |             ~                   
   62 |             else{
      |             ~~~~~               
   63 |                 b2=0;
      |                 ~~~~~           
   64 |                 break;
      |                 ~~~~~~          
   65 |             }
      |             ~                   
   66 |             cur++;
      |             ~~~~~~              
   67 |         }
      |         ~                       
   68 |         if(b2){
      |         ~~~~~~~                 
   69 |             vec.push_back({mx-m,mx});
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~
   70 |         }
      |         ~                       
   71 |     }
      |     ~                           
   72 |     int cur=0;
      |     ~~~~~~~~~~                  
   73 |     int ret=0;
      |     ~~~~~~~~~~                  
   74 |     f(0,vec.size()){
      |     ~~~~~~~~~~~~~~              
paint.cpp:74:5: note: in expansion of macro 'f'
   74 |     f(0,vec.size()){
      |     ^
paint.cpp:75:13: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   75 |         if(i<vec.size()-1&&vec[i+1].first<=cur)continue;
      |            ~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Incorrect 1 ms 212 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Incorrect 1 ms 212 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Incorrect 1 ms 212 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Incorrect 1 ms 212 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Incorrect 1 ms 212 KB Output isn't correct
7 Halted 0 ms 0 KB -