codechef 编译器如何工作?
How codechef compiler works?
I want to know how the codechef compiler works. Actually not only codechef compiler how other competitive platforms compilers works on backend. Because the output which I used to get on my local compiler sometimes differ from the online compilers specifically on codechef.
例如,在我的本地编译器上,当我 运行 下面的代码时,我得到了正确的输出:
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
// your code goes here
int t;
cin >> t;
while (t--)
{
int val, N, Z, count = 0, evacuate = 0;
vector<int> v;
cin >> N >> Z;
for (int i = 0; i < N; i++)
{
cin >> val;
v.push_back(val);
}
std::make_heap(v.begin(), v.end());
while (Z > 0)
{
int power = v.front();
Z = Z - power;
std::pop_heap(v.begin(), v.end());
v.pop_back();
power = power / 2;
if (power)
{
v.push_back(power);
std::push_heap(v.begin(), v.end());
}
else if(power == 0 && Z > 0){
evacuate = 1;
break;
}
if (Z < 0)
{
count++;
break;
}
count++;
}
if (evacuate)
cout << "Evacuate" << endl;
else
cout << count << endl;
}
}
当我在 codechef 编译器上 运行 解决相同的代码时 codechef problem 我得到了意外的输出(只有 0)
此外,代码在 cpp.sh 上运行。
CodeChef 编译器如何工作以及两者的输出有何不同?可能问题也可能出在代码上,但在本地,我得到了手动提供的输入的正确输出。
刚检查过,您的代码工作正常。问题是你没有任何输入。
勾选“自定义输入”,然后输入“1 5 25 7 13 8 17 3”,你会看到预期的结果。
编辑:
为此,您首先要选中红色圆圈中的复选框,然后下方会显示一个文本框,您可以在蓝色框中输入您的测试用例。
I want to know how the codechef compiler works. Actually not only codechef compiler how other competitive platforms compilers works on backend. Because the output which I used to get on my local compiler sometimes differ from the online compilers specifically on codechef.
例如,在我的本地编译器上,当我 运行 下面的代码时,我得到了正确的输出:
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
// your code goes here
int t;
cin >> t;
while (t--)
{
int val, N, Z, count = 0, evacuate = 0;
vector<int> v;
cin >> N >> Z;
for (int i = 0; i < N; i++)
{
cin >> val;
v.push_back(val);
}
std::make_heap(v.begin(), v.end());
while (Z > 0)
{
int power = v.front();
Z = Z - power;
std::pop_heap(v.begin(), v.end());
v.pop_back();
power = power / 2;
if (power)
{
v.push_back(power);
std::push_heap(v.begin(), v.end());
}
else if(power == 0 && Z > 0){
evacuate = 1;
break;
}
if (Z < 0)
{
count++;
break;
}
count++;
}
if (evacuate)
cout << "Evacuate" << endl;
else
cout << count << endl;
}
}
当我在 codechef 编译器上 运行 解决相同的代码时 codechef problem 我得到了意外的输出(只有 0)
此外,代码在 cpp.sh 上运行。
CodeChef 编译器如何工作以及两者的输出有何不同?可能问题也可能出在代码上,但在本地,我得到了手动提供的输入的正确输出。
刚检查过,您的代码工作正常。问题是你没有任何输入。
勾选“自定义输入”,然后输入“1 5 25 7 13 8 17 3”,你会看到预期的结果。
编辑:
为此,您首先要选中红色圆圈中的复选框,然后下方会显示一个文本框,您可以在蓝色框中输入您的测试用例。