'g++ compilation won't end
I've been trying solve some problem with this code. In my machine, It compiled with no errors with
g++ "File_name.cpp"
but on the judges machine it uses this command
g++ -g -O2 -std=gnu++17 -static "File_name.cpp"
and it won't end compiling hence Time limit exceeded. I used the those flags too and it won't finish compiling either.
Anyone Who can help.
#include<iostream>
#include<string>
#include<utility>
#include<vector>
#include<queue>
using namespace std;
pair<int,int> maxi;
void bfs(vector<vector<char>> &Adj_List, pair<int,int> start);
int main(){
vector<pair<int,int>> starts;
cin >> maxi.first >> maxi.second;
vector<vector<char>> graph(maxi.first);
char single;
for(int i = 0; i < maxi.first; i++){
for(int j = 0; j < maxi.second; j++){
cin >> single;
graph[i].push_back(single);
if(graph[i][j] == 'V') starts.push_back({i, j});
}}
for(auto k:starts) bfs(graph, k);
for(int i = 0; i < maxi.first; i++){
for(int j = 0; j < maxi.second; j++) cout << graph[i][j] << ' ';
cout << endl;
}
return 0;
}
void bfs(vector<vector<char>> &graph, pair<int,int> start){
queue<pair<int,int>> q;
q.push({start.first, start.second});
while(!q.empty()){
pair<int,int> temp = q.front();
q.pop();
graph[temp.first][temp.second] = 'V';
if(temp.first != maxi.first-1)
if(graph[temp.first+1][temp.second] != '#') q.push({temp.first+1,temp.second});
else{
if(temp.second != maxi.second-1 && graph[temp.first][temp.second+1] != '#' && graph[temp.first][temp.second+1] != 'V')
q.push({temp.first,temp.second+1});
if(temp.second != 0 && graph[temp.first][temp.second-1] != '#' && graph[temp.first][temp.second-1] != 'V')
q.push({temp.first,temp.second-1});
}
}
}
Solution 1:[1]
as @user17732522 mentioned This problem is not reproducible. because the problem was with the judge side.....rather than uploading the file, copying the code directly to the site fixed the problem.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Nahom Derese |