fish_love_your_cats
2021-01-18 09:42breakfastNumber
class Solution {
public:
static bool cmp(int a, int b) {
return a >= b;
}
int breakfastNumber(vector<int>& staple, vector<int>& drinks, int x) {
int ans = 0;
int stapleLen = staple.size();
cout << stapleLen << endl;
int drinksLen = drinks.size();
cout << drinksLen << endl;
sort(staple.begin(), staple.end(), cmp);
sort(drinks.begin(), drinks.end());
int j = 0;
for (int i = 0; i < stapleLen; i++) {
ans += j;
ans %= 1000000007;
for (; j < drinksLen; j++) {
if (staple[i] + drinks[j] <= x) {
ans++;
ans %= 1000000007;
} else {
break;
}
}
}
return ans;
}
};
提示信息:
=================================================================
==42==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x7f22768b87fc at pc 0x00000034d6ad bp 0x7ffc746101b0 sp 0x7ffc746101a8
READ of size 4 at 0x7f22768b87fc thread T0
#6 0x7f2279d720b2 (/lib/x86_64-linux-gnu/libc.so.6+0x270b2)
0x7f22768b87fc is located 4 bytes to the left of 524288-byte region [0x7f22768b8800,0x7f2276938800)
allocated by thread T0 here:
#6 0x7f2279d720b2 (/lib/x86_64-linux-gnu/libc.so.6+0x270b2)
Shadow bytes around the buggy address:
0x0fe4ced0f0a0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0fe4ced0f0b0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0fe4ced0f0c0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0fe4ced0f0d0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0fe4ced0f0e0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
=>0x0fe4ced0f0f0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa[fa]
0x0fe4ced0f100: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0fe4ced0f110: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0fe4ced0f120: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0fe4ced0f130: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0fe4ced0f140: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa
Freed heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
Container overflow: fc
Array cookie: ac
Intra object redzone: bb
ASan internal: fe
Left alloca redzone: ca
Right alloca redzone: cb
Shadow gap: cc
==42==ABORTING
类解决方案 { 公共: 静态bool cmp(int a,int b) { 返回a >= b; } int breakfastNumber(vector<int>& stub,vector<int>& 饮料,int x) { int = 0; int stapleLen = 订书钉.尺寸 (); cout <stapleLen <endl; int drinksLen = 饮料尺寸 (); cout << drinksLen <endl; sort (studin.begin(),stapin.end(),cmp); 排序 (饮料.开始 () 、饮料.结束 ()); int j = 0; for (int i = 0; i < stapleLen; i ++) { ans + = j; ans % = 1000000007; 用于 (; j < drinksLen; j ++) { 如果 (主食 [i] + 饮料 [j] <= x) { ans ++; ans % = 1000000007; } else { 打破; } } } 退货; } }; 提示信息: ================================================================= = = 42 = ERROR: AddressSanitizer: 堆-缓冲区-在pc 0x00000034d6ad bp处的地址0x7f22768b87fc 746101b0 sp 0x7ffc746101a8 在0x7f22768b87fc线程T0读取大小为4 #6 0x7f2279d720b2 (/lib/x86_64-linux-gnu/libc.so.6 + 0x270b2) 0x7f22768b87fc位于524288字节区域左侧4字节 [0x7f22768b8800,0x7f2276938800) 由线程T0在这里分配: #6 0x7f2279d720b2 (/lib/x86_64-linux-gnu/libc.so.6 + 0x270b2) 围绕越野车地址的阴影字节: 0x0fe4ced0f0a0: fa 0x0fe4ced0f0b0: fa 0x0fe4ced0f0c0: fa 0x0fe4ced0f0d0: fa 0x0fe4ced0f0e0: fa =>0x0fe4ced0f0f0: fa[fa] 0x0fe4ced0f100: 00 0x0fe4ced0f110: 00 0x0fe4ced0f120: 00 0x0fe4ced0f130: 00 0x0fe4ced0f140: 00 阴影字节图例 (一个阴影字节代表8个应用程序字节): 可寻址: 00 部分可寻址: 01 02 03 04 05 06 07 堆左redzone: fa 自由堆区域: fd 堆栈左redzone: f1 堆栈中redzone: f2 堆栈右红区: f3 返回后堆栈: f5 作用域后堆栈使用: f8 全球redzone: f9 全球init订单: f6 被用户中毒: f7 容器溢出: fc 数组cookie: ac Intra对象redzone: bb ASan内部: fe 左alloca redzone: ca 右alloca redzone: cb 阴影间隙: cc = = 42 = = 引产
- 点赞
- 回答
- 收藏
- 复制链接分享