제출 #864387

#제출 시각아이디문제언어결과실행 시간메모리
864387gutzzyPohlepko (COCI16_pohlepko)C++14
55 / 80
1096 ms21692 KiB
#include <bits/stdc++.h>
using namespace std;

int n;
int m;
string ans;
vector<vector<char>> board;

bool possible(string curr, string ans)
{

    for (int i=0; i<curr.size(); i++)
        if (curr[i]<ans[i]) return true;
        else if (curr[i]>ans[i]) return false;
        
    return true;
}


void bt(int i, int j, string cur){
    if(i==n-1 and j==m-1){
        ans = min(ans, cur);
        return;
    }
    if(i==n-1){
        j++;
        cur+=board[i][j];
        if(possible(cur,ans)){
            bt(i,j,cur);
        }
        return;
    }
    else if(j==m-1){
        i++;
        cur+=board[i][j];
        if(possible(cur,ans)){
            bt(i,j,cur);
        }
        return;
    }
    else{
        if(board[i+1][j]!=board[i][j+1]){
            if(board[i+1][j]<board[i][j+1]) i++;
            else j++;
            cur += board[i][j];
            if(possible(cur,ans)){
                bt(i,j,cur);
            }
            return;
        }
        else{
            cur += board[i+1][j];
            if(possible(cur,ans)){
                bt(i+1,j,cur);
                bt(i,j+1,cur);
            }
            return;
        }
    }
}

int main(){
    cin >> n >> m;
    board = vector<vector<char>>(n,vector<char>(m));
    
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            cin >> board[i][j];
        }
    }

    for(int i=0; i<n+m-1; i++)
        ans += "{";
    
    string c;
    c += board[0][0];
    
    bt(0,0,c);
    
    cout << ans << endl;
    
    return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

pohlepko.cpp: In function 'bool possible(std::string, std::string)':
pohlepko.cpp:12:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 |     for (int i=0; i<curr.size(); i++)
      |                   ~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...