30分,7个TLE

P1469 找筷子

老哥 看看题解 ~~话说为啥都喜欢做这种卡内存邪恶题啊~~
by 鏡音リン @ 2022-09-01 10:57:32


请注意本题的空间限制为 4 Mb。
by anonymous_letter @ 2022-09-01 10:57:33


我知道限制为4MB,自己也发现,答案就是异或值, 异或算法也应该是最快,最节约内存的算法。 怎么还只有3个AC? 这是怎么搞的?
by caojiaming @ 2022-09-01 11:02:52


@[caojiaming](/user/775551) 您可以不使用数组。 ```cpp #include <iostream> #include <algorithm> #include <cstring> #include <cstdio> #include <string.h> #include <bitset> #include <cmath> using namespace std; int main() { int a,ans=0; cin>>a; //int k[a]; 不用数组 for(int i=0;i<a;i++) { int k; //直接这样不香吗 cin>>k; ans^=k; } cout<<ans; return 0; } ```
by liangbowen @ 2022-09-01 11:24:21


原因显然是:1e7的数组比4mb大多了
by liangbowen @ 2022-09-01 11:25:09


4MB 内存不是让你开一个大小为 $10^7$ 的局部变量数组的; $10^7$ 级别的读入量还用不关流的 cin/cout,很容易 TLE 的吧。
by whhsteven @ 2022-09-01 11:56:07


铃酱楼下,好耶!b( ̄▽ ̄)d 
by whhsteven @ 2022-09-01 11:56:43


```cpp #include <iostream> #include <algorithm> #include <cstring> #include <cstdio> #include <string.h> #include <bitset> #include <cmath> using namespace std; int main() { int a,ans=0; cin>>a; int k; for(int i=0;i<a;i++) { cin>>k; ans^=k; } cout<<ans; return 0; } ``` 这次我没用数组,可还是有一个点(1点)没过,这点还是TLE。 这点到底怎么过啊?
by caojiaming @ 2022-09-01 11:57:26


> 请注意数据读入对程序效率造成的影响。 关流!
by whhsteven @ 2022-09-01 11:58:40


要不,我就改用char或short定义变量, 这样占的空间少一些
by caojiaming @ 2022-09-01 12:04:17


| 下一页