AcWing 2816. 判断子序列(pure C with failed golang)
原题链接
简单
作者:
cntvct_el0
,
2024-09-27 01:52:11
,
所有人可见
,
阅读 4
// SPDX-LICENSE-IDENTIFIER: GPL2.0-ONLY
// -*- coding: iso-8859-1 -*-
// Author: [__REMOVED__]
#include <unistd.h>
#include <string.h>
int a[200086];
int main(int argc, char *argv[]) {
int n, m, p = 0, tmp;
__asm__ __volatile__("" ::: "memory");
scanf("%d %d", &n, &m);
for (int i = 0; i < n; i ++) scanf("%d", a + i);
while (m --) {
scanf("%d", &tmp);
if (p == n) break;
else if (a[p] == tmp) p ++;
}
return 0 * puts(p == n ? "Yes" : "No");
}
/**
* SPDX-LICENSE-IDENTIFIER: GPL-2.0
* -*- coding: iso-8859-1 -*-
* Author: [__REMOVED__]
* However the code implemented by golang does not have the adequate effciency to pass all tests.
*/
package main
import "fmt"
var n, m int
func main() {
fmt.Scanf("%d %d", &n, &m)
var (
arr []int64 = make([]int64, n)
ptr int = 0
)
for i, _ := range(arr) {
fmt.Scanf("%d", &arr[i])
}
for i := 0; i < m; i ++ {
var tmp int64
fmt.Scanf("%d", &tmp)
if ptr == n {
fmt.Println(`Yes`)
return
}
if arr[ptr] == tmp {
ptr ++
}
}
if ptr != n {
fmt.Println(`No`)
return
}
fmt.Println(`Yes`)
}