在 mono 中编译时 C# List 出现问题(与作业相关)
我承认这是我的作业。任务声明说我必须编写一个程序来查找将由标准输入输入的图的拓扑顺序。然后我需要将其提交到教授的服务器上进行评分。
现在不是算法问题了。这更多的是一个技术问题。在我的计算机中,我使用 .NET 编译器 (csc),而教授的评分机使用某种形式的 mono。
效果很好,直到评分者说我得了 30/100。我的一个朋友建议我使用分级机的“手动输入系统”,所以在这里,我让它为邻接列表创建 100000 个列表的数组。
几秒钟后,评分者报告说我的程序崩溃了。
Stacktrace:
at (wrapper managed-to-native) object.__icall_wrapper_mono_object_new_fast (intptr) <0x00004>
at (wrapper managed-to-native) object.__icall_wrapper_mono_object_new_fast (intptr) <0xffffffff>
at System.Exception.ToString () <0x00026>
at (wrapper runtime-invoke) object.runtime_invoke_object__this__ (object,intptr,intptr,intptr) <0xffffffff>
at (wrapper managed-to-native) object.__icall_wrapper_mono_object_new_fast (intptr) <0x00004>
at (wrapper managed-to-native) object.__icall_wrapper_mono_object_new_fast (intptr) <0xffffffff>
at System.Exception.ToString () <0x00026>
at (wrapper runtime-invoke) object.runtime_invoke_object__this__ (object,intptr,intptr,intptr) <0xffffffff>
at (wrapper managed-to-native) object.__icall_wrapper_mono_object_new_fast (intptr) <0x00004>
at (wrapper managed-to-native) object.__icall_wrapper_mono_object_new_fast (intptr) <0xffffffff>
at System.Exception.ToString () <0x00026>
at (wrapper runtime-invoke) object.runtime_invoke_object__this__ (object,intptr,intptr,intptr) <0xffffffff>
at (wrapper managed-to-native) object.__icall_wrapper_mono_object_new_fast (intptr) <0x00004>
at (wrapper managed-to-native) object.__icall_wrapper_mono_object_new_fast (intptr) <0xffffffff>
at System.Exception.ToString () <0x00026>
at (wrapper runtime-invoke) object.runtime_invoke_object__this__ (object,intptr,intptr,intptr) <0xffffffff>
at (wrapper managed-to-native) object.__icall_wrapper_mono_object_new_fast (intptr) <0x00004>
at (wrapper managed-to-native) object.__icall_wrapper_mono_object_new_fast (intptr) <0xffffffff>
at System.Exception.ToString () <0x00026>
at (wrapper runtime-invoke) object.runtime_invoke_object__this__ (object,intptr,intptr,intptr) <0xffffffff>
at (wrapper managed-to-native) object.__icall_wrapper_mono_object_new_fast (intptr) <0x00004>
at (wrapper managed-to-native) object.__icall_wrapper_mono_object_new_fast (intptr) <0xffffffff>
at System.Exception.ToString () <0x00026>
at (wrapper runtime-invoke) object.runtime_invoke
这对我来说有点奇怪和不安,但我还没有找到答案。再说一次,这个程序在我的电脑上运行得非常好。
这是我的计划的一部分:
using System;
using System.Collections;
using System.Collections.Generic;
class topo{
public static void Main(){
string[] ST = Console.ReadLine().Split(' ');
int N=Convert.ToInt32(ST[0]), M=Convert.ToInt32(ST[1]);
int[] ins = new int[N]; //node's total in-degrees
List<int>[] E = new List<int>[N];
for(int n=0;n<N;n++)
E[n] = new List<int>();
for(int m=0;m<M;m++){
ST = Console.ReadLine().Split(' ');
int u = Convert.ToInt32(ST[0]);
int v = Convert.ToInt32(ST[1]);
E[u-1].Add(v-1);
ins[v-1]++;
}
Queue S = new Queue();
List<int> L = new List<int>(); //result list
for(int n=0;n<N;n++){
//add stranded nodes directly and don't process it
if(ins[n]==0 && E[n].Count==0)
L.Add(n);
//put into queue
else if(ins[n]==0)
S.Enqueue(n);
}
while(S.Count>0){
int n = (int) S.Dequeue();
L.Add(n);
foreach(int m in E[n])
if(--ins[m]==0)
S.Enqueue(m);
}
foreach(int n in L)
Console.WriteLine(n+1);
}
}
非常感谢您,我感谢您的每一个回复。
编辑:我又看了一眼分级机的输出,看看我是否遗漏了任何东西,确实我漏掉了。它说“syscal:2”,但我只知道“程序没有正常退出”。
编辑#2:我尝试让程序尝试创建各种大小的列表数组,范围从 5000、10000 等,在 40000 之后,“手动输入系统”表示程序遇到了 System.OutOfMemoryException。通过进一步研究允许学生进入的评分器的各个部分,教授似乎错误地配置了他的评分参数,并给我们提供了比宣布的更少的内存。 (他说“32MB”,但程序在大约 16MB 时崩溃)
我已向他报告了该错误,他(现在)正在调查该问题。
I'll admit this is my homework. The task statement said I have to write a program that finds a topological order of a graph which would be inputted by standard input. Then I need to submit it to be graded on the professor's server.
Now it's not the algorithm problem. It's more of a technical problem. In my computer, I use .NET compiler (csc) while the professor's grading machine uses some form of mono.
It works well, until the grader said I got 30/100. A friend of mine suggested that I use the grader's "manual input system", so here I go, I made it create array-of-100000 lists for the adjacency list.
The grader, after a few seconds, reported that my program has crashed.
Stacktrace:
at (wrapper managed-to-native) object.__icall_wrapper_mono_object_new_fast (intptr) <0x00004>
at (wrapper managed-to-native) object.__icall_wrapper_mono_object_new_fast (intptr) <0xffffffff>
at System.Exception.ToString () <0x00026>
at (wrapper runtime-invoke) object.runtime_invoke_object__this__ (object,intptr,intptr,intptr) <0xffffffff>
at (wrapper managed-to-native) object.__icall_wrapper_mono_object_new_fast (intptr) <0x00004>
at (wrapper managed-to-native) object.__icall_wrapper_mono_object_new_fast (intptr) <0xffffffff>
at System.Exception.ToString () <0x00026>
at (wrapper runtime-invoke) object.runtime_invoke_object__this__ (object,intptr,intptr,intptr) <0xffffffff>
at (wrapper managed-to-native) object.__icall_wrapper_mono_object_new_fast (intptr) <0x00004>
at (wrapper managed-to-native) object.__icall_wrapper_mono_object_new_fast (intptr) <0xffffffff>
at System.Exception.ToString () <0x00026>
at (wrapper runtime-invoke) object.runtime_invoke_object__this__ (object,intptr,intptr,intptr) <0xffffffff>
at (wrapper managed-to-native) object.__icall_wrapper_mono_object_new_fast (intptr) <0x00004>
at (wrapper managed-to-native) object.__icall_wrapper_mono_object_new_fast (intptr) <0xffffffff>
at System.Exception.ToString () <0x00026>
at (wrapper runtime-invoke) object.runtime_invoke_object__this__ (object,intptr,intptr,intptr) <0xffffffff>
at (wrapper managed-to-native) object.__icall_wrapper_mono_object_new_fast (intptr) <0x00004>
at (wrapper managed-to-native) object.__icall_wrapper_mono_object_new_fast (intptr) <0xffffffff>
at System.Exception.ToString () <0x00026>
at (wrapper runtime-invoke) object.runtime_invoke_object__this__ (object,intptr,intptr,intptr) <0xffffffff>
at (wrapper managed-to-native) object.__icall_wrapper_mono_object_new_fast (intptr) <0x00004>
at (wrapper managed-to-native) object.__icall_wrapper_mono_object_new_fast (intptr) <0xffffffff>
at System.Exception.ToString () <0x00026>
at (wrapper runtime-invoke) object.runtime_invoke
This is kinda strange and unsettling to me, but I have yet to find an answer for this. Again, this program worked really fine on my PC.
This is my part of the program:
using System;
using System.Collections;
using System.Collections.Generic;
class topo{
public static void Main(){
string[] ST = Console.ReadLine().Split(' ');
int N=Convert.ToInt32(ST[0]), M=Convert.ToInt32(ST[1]);
int[] ins = new int[N]; //node's total in-degrees
List<int>[] E = new List<int>[N];
for(int n=0;n<N;n++)
E[n] = new List<int>();
for(int m=0;m<M;m++){
ST = Console.ReadLine().Split(' ');
int u = Convert.ToInt32(ST[0]);
int v = Convert.ToInt32(ST[1]);
E[u-1].Add(v-1);
ins[v-1]++;
}
Queue S = new Queue();
List<int> L = new List<int>(); //result list
for(int n=0;n<N;n++){
//add stranded nodes directly and don't process it
if(ins[n]==0 && E[n].Count==0)
L.Add(n);
//put into queue
else if(ins[n]==0)
S.Enqueue(n);
}
while(S.Count>0){
int n = (int) S.Dequeue();
L.Add(n);
foreach(int m in E[n])
if(--ins[m]==0)
S.Enqueue(m);
}
foreach(int n in L)
Console.WriteLine(n+1);
}
}
Thank you very much, and I appreciate any and every response.
Edit: I took another look at the grader's output to see if I missed anything, and indeed I did. It said "syscal: 2", but all I know about it is that "the program didn't exit normally."
Edit #2: I've tried making the program attempt to make various sizes of the array-of-list, ranging from 5000, 10000, etc. and after 40000 the "manual input system" said the program got a System.OutOfMemoryException. With further look into various parts of the grader that the students are allowed into, it seems that prof misconfigured his grading parameters and gave us less memory than announced. (He said "32MB", but the program crashes at about 16MB)
I've reported the error to him and he is (right now) looking into it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果
u
或v
的值小于 1,以下代码将会失败。因为
u-1
或v- 1
将为负数,这将引发异常。The following code is going to fail if the value of
u
orv
is less than 1.Because
u-1
orv-1
is going to be negative, and that will throw an exception.跟进:这是轶事,自我回答,而且很晚了,因为我刚刚意识到可以回答自己。后来我被告知我超出了评分系统强制执行的内存限制。然而,在我的例子中,异常是相当神秘的,评分者没有报告这个问题。 (它只是将我标记为不正确。)
我也很粗心,没有意识到较小的输入有效,这就是为什么我得到 30/100 而不是零分。
对于未来的读者:在自动评分机环境中编程时,请确保您的程序没有超出内存限制,内存限制可能存在但您可能不知道(即没有写在问题陈述中)。
Followup: This is anecdotal, self-answer, and very late because I just realized that it's okay to answer myself. I was later notified that I went over the memory limit enforced by the grading system. However, the exception was quite cryptic in my case and the grader did not report this issue. (It marked me only as incorrect.)
I was also quite careless to not realize that smaller inputs worked, and that's why I got 30/100 and not zero points.
For future readers: When programming in an automatic-grader environment, please make sure your program does not go over the memory limit, which may be there but may not be known to you (i.e. not written in problem statement).